I'm trying to send this html email and for some reason it won't send when there's a link in the body. The only difference between these two files seems to be that one has a link in the body. If I put the same thing in the subject it sends fine.
Works perfectly:
//mail body and subject
$mail_body = "Test Email with no link.";
$subject = "Test email with no link";
//recipient
$recipient = "myemail@mydomain.com";
//headers to send HTML email
$header = "MIME-Version: 1.0
" ;
$header = $header . "Content-Type: text/html; charset="\iso-8859-1\"
";
$header = $header . 'From: admin@test.com';
//send the message
mail($recipient, $subject, $mail_body, $header) or die('mail could not be sent'); //mail command :)
echo('Good Test');
Does Not work:
//mail body and subject
$mail_body = "Test Email with link. <a href=\"http://www.google.com\">google</a>";
$subject = "Test email with with link. ";
//recipient
$recipient = "myemail@mydomain.com";
//headers to send HTML email
$header = "MIME-Version: 1.0
" ;
$header = $header . "Content-Type: text/html; charset=\"iso-8859-1\"
";
$header = $header . 'From: admin@test.com';
//send the message
mail($recipient, $subject, $mail_body, $header) or die('mail could not be sent'); //mail command :)
echo('Bad Test');
You need to escape the quotes in your e-mail address. Check the backslashes:
$mail_body = "Test Email with link. <a href=\"http://www.google.com\">google</a>";
It looks like the href in your $mail_body has an unescaped double quote. Have you tried:
$mail_body = "Test Email with link. <a href=\"http://www.google.com\">google</a>";
Note the backslashes.
You have 4 quotes (") in the $mail_body tag - it tries to assign the information between the first 2 quotes only, then expects something like a semi colon (;) at the end or append operator (.), when it doesn't see one of these it doesn't know what to do. It also should be a problem in the 2nd header ($header= $header . "Content-Type: text/html; charset="iso-88598-1" ";
The simplest way to do this is:
Change the following:
FROM THIS:
$mail_body = "Test Email with link. <a href="http://www.google.com">google</a>";
TO THIS:
$mail_body = "Test Email with link. <a href=\"http://www.google.com\">google</a>";
FROM THIS: $header = $header . "Content-Type: text/html; charset="iso-8859-1" ";
TO THIS: $header = $header . "Content-Type: text/html; charset=\"iso-8859-1\" ";