0

I wrote a php routine not long ago to send an HTML email for the purposes of email verification.

In it was an img tag using a logo from the internet, followed by "Thank you, click the button below to verify your email address." I had some trouble at first, but you guys straightened me out on it (Sending HTML mail not working). When I got the answer, I kicked myself for not seeing it myself.

Using what I learned, I tried something similar on a different project. Only this time I used an image from my website's folder. It would not send. If I took out my image and put in the old image, it would work. If I put in both images, it would work. If I took out the old image, it would fail. If I took out both of the images, it would work. Thinking that it might be a line length issue the email server was choking on (the local image had a long file name, though the path was short), I shortened the name of the image file. It still failed. I changed the name of the image file again by a few characters, and it failed. It seems like this new image is cursed.

I'm having some problems again with a different email. I can't give the full text of the code without revealing client info that should be protected. But I am going to include some so you can see that I'm trying to keep line lengths under 70 characters.

function sendVerificationEmail($email, $verificationcode) {
  $email2 = str_replace("@","%40",$email);
  $to = $email;
  $subject = 'aaaa bbbbb ccccc Validation';  //text replaced to protect client and maintain line lengths...

  $headers  = "From: " . strip_tags('dddddd@eeee.org') . "\r\n";
  $headers .= "Reply-To: ". strip_tags('dddddd@eeee.org') . "\r\n";
  $headers .= "CC: \r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

  $message =  "<html><body>\r\n";
  //$message .= "test#10<br>\r\n";
  //$message .= "<img src='http://www.012345678901234.com/eeee/images/eeeelogo_short.png'>";
  //$message .= "<img src='http://www.012345678901234.com/eeee/images/eeeelogo.png'>";
  //$message .= '<img src="http://www.ffffffff.com/22221111004444/assets/images/logo.png"><br>';
  $message .= "\r\n<h2>Thank you!</h2>\r\n";
  $message .= 'Thank you for registering an account with gggg hhhhh iiiiii! ';
  $message .= 'Please verify your email address by clicking the button below.<br><br>';
  $message .= '<a href="http://www.012345678901234.com/eeee/verifyemail.php?email='.$email2.'&code='.$verificationcode.'"><img src="http://www.012345678901234.com/images/verifyemail.png"></a>';
  $message .= "</body></html>\r\n";


  $message = wordwrap($message, 70, "\r\n");
  mail($to, $subject, $message, $headers);
}

The second and third items commented out are my problem images. What do you suggest I look at first?

SH

Community
  • 1
  • 1
Superhuman
  • 149
  • 1
  • 2
  • 13
  • Why you try to `wordwrap` html code? It can broke html attributes, like `img[src]` – vp_arth Jun 07 '16 at 19:12
  • I read an online guide to HTML mail and it suggested that the lines be maintained 70 characters or less. I removed this line and it still didn't work. – Superhuman Jun 10 '16 at 00:49

1 Answers1

0
//$message .= "<img src='http://www.012345678901234.com/eeee/images/eeeelogo_short.png'>";
//$message .= "<img src='http://www.012345678901234.com/eeee/images/eeeelogo.png'>";
//$message .= '<img src="http://www.ffffffff.com/22221111004444/assets/images/logo.png"><br>';

If the first works, why don't you double quote your second and third? And single quote your img src.

Like this:

//$message .= '<img src="http://www.012345678901234.com/eeee/images/eeeelogo_short.png">';
//$message .= '<img src="http://www.012345678901234.com/eeee/images/eeeelogo.png">';
//$message .= '<img src="http://www.ffffffff.com/22221111004444/assets/images/logo.png"><br>';

Rest of the code seems fine by me (could be wrong off course)

J. DKYSR
  • 80
  • 1
  • 14
  • In the code snippet that I sent, the commented "test #" was what I considered the first. The img from ffffffff.com is the one that worked. And as long as it was in the message string, the email would send. Even if it was with both images. But I'll try anything at this point. – Superhuman Jun 07 '16 at 16:08
  • If the last one works, then try putting it all in single quotes and the src in single :p?I edited the code I posted... – J. DKYSR Jun 07 '16 at 19:00
  • I changed the quotes as described @J. DKYSR, it still didn't work. – Superhuman Jun 10 '16 at 00:47
  • Perhaps this can help? -- http://stackoverflow.com/questions/536838/php-attaching-an-image-to-an-email -- I find it weird that one image works, yet with the same setting another won't... – J. DKYSR Jun 10 '16 at 08:09