We've recently upgraded to a Plesk Parallel Linux Server and it appears as if the PHP settings are ignoring headers! The emails are receiving fine, but display the HTML tags.
The phpInfo() file can be viewed here: https://www.pressgofer.com/phpInfo.php
The PHP itself should be okay, but have included it here anyway.
PHP Mail Code
$email = "example#example.com";
$message = "<h1 style='font-family:Helvetica,Arial;font-size:17px'>Your account has a password reset request</h1>";
$headers = "From: noreply#pressgofer.com \r\n";
$headers .= "Reply-To: noreply#pressgofer.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($email, "Reset password notification", $message, $headers);
Many thanks,
Nick
your phpinfo shows that mail.add_x_header is OFF. you need to turn it on
To enable the X-Mail header, set mail.add_x_header to 1 in your php.ini
<?php
$to = "yourplace#somewhere.com";
$subject = "My HTML email test.";
$headers = "From: sinha.ksaurabh#gmail.com\r\n";
$headers .= "Reply-To: sinha.ksaurabh#gmail.com\r\n";
$headers .= "Return-Path: sinha.ksaurabh#gmail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "<h1> This is a test </h1>";
$message .= "</body></html>";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
sending mail from php: headers are interpreted as body?
Issue was associated with MIME type and server interpretation- no \r needed.
Related
I know there are a few similar questions to this but I just can't get it working.
Ok, I have a list of emails grabbed from my database in a variable called $emailList.
I can get my code to send an email from a form if I put the variable in the $to section but
I cannot get it to work with bcc. I've even added an email to the $to incase it was that but it doesn't make a difference.
Here is my code.
$to = "name#mydomain.com";
$subject .= "".$emailSubject."";
$headers .= 'Bcc: $emailList';
$headers = "From: no-reply#thepartyfinder.co.uk\r\n" . "X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}
I've tried both codes:
$headers .= 'Bcc: $emailList';
and
$headers .= 'Bcc: '.$emailList.';
It's not that the emails aren't separated because they are. I know they are because it works if I put $emailList in the $to section.
I Should add, ignore the $message bits and the HTML stuff. I've not provided all of that so that is why it's missing from this code.
You have $headers .= '...'; followed by $headers = '...';; the second line is overwriting the first.
Just put the $headers .= "Bcc: $emailList\r\n"; say after the Content-type line and it should be fine.
On a side note, the To is generally required; mail servers might mark your message as spam otherwise.
$headers = "From: no-reply#thepartyfinder.co.uk\r\n" .
"X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Bcc: $emailList\r\n";
You were setting BCC but then overwriting the variable with the FROM
$to = "name#mydomain.com";
$subject .= "".$emailSubject."";
$headers .= "Bcc: ".$emailList."\r\n";
$headers .= "From: no-reply#thepartyfinder.co.uk\r\n" .
"X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}
I am not sure if anyone can help me with this issues but I currently have a php mailing form. everything works great, I am trying to setup Cc options.
code.
$subject = "Name #$name_id test data";
$mailer ='Company <Support#company.com>';
$headers = "From: $mailer \r\n";
$headers .= "Cc: $cc \r\n";
$headers .= "Reply-To: ". strip_tags($mailer) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body style="background:#eeeeee">';
mail($emailto, $subject, $message, $headers);
cc var is $cc=$VAR["cc_user"]; which is linked to html form. so here is I enter an email address in the html input form and submit, it works. if I leave blank, email does not send. can anyone help me with this.
Thanks so much.
Fixed..
$emailto= $sql['CUSTOMER_EMAIL'].", ".$VAR["cc_user"];
Hi I am trying to send an entire webpage via e-mail. I receive it in Mail.app in my Mac and i can see it fine. But when i see it in gmail or hotmail, It didn't get the styles
How can I do this correctly. Or how to transform the webpage to PDF or PNG and send it via Mail [I can't install anything to the server]
Edit: It send all the information but without Style
My code:
$mail = $_POST['mail'];
if(($Content = file_get_contents("http://google.com")) === false) {
$Content = "";
}
$Headers = "MIME-Version: 1.0\n";
$Headers .= "Content-type: text/html; charset=iso-8859-1\n";
$Headers .= "From: a#a.com <a#a.com>\n";
$Headers .= "Reply-To: a#a.com\n";
$Headers .= "X-Sender: <a#a.com>\n";
$Headers .= "X-Mailer: PHP\n";
$Headers .= "X-Priority: 1\n";
$Headers .= "Return-Path: <a#a.com>\n";
if(mail($mail, $subject, $Content, $Headers) == false) {
//Error
}
Thanks
Remove all external style sheets . All the styles on the page should be inline or defined within the page
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Sending HTML email from PHP
I am sending emails using php through my gmail account. And I am using ssmtp other than sendmail. I am using following php code to send the mail.
$to = "mymail#gmail.com";
$from = "mymail#gmail.com";
$subject = "Testing mail";
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
$headers = "From:" . $from;
$message = "<html><body><head></head>";
$message .= "<h1>Hello, World!</h1>";
$message .= "</body></html>";
if(mail($to,$subject,$message,$headers)){
echo "Mail Sent.";
} else {
echo 'failed';
}
But I am getting a mail like below
<html><body><head></head><h1>Hello, World!</h1></body></html>
What may be the reason for it? I am using ssmtp MTA in Ubuntu.
Try using the following in your code
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
This link will be most helpful
Sending HTML email with PHP
You are using header (singular) and headers (plural) indistinctly. The correct way is using plural for the headers:
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
This is a good reading:
http://css-tricks.com/sending-nice-html-email-with-php/
use this
<?php
$to = "mymail#gmail.com";
$from = "mymail#gmail.com";
$subject = "Testing mail";
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header .= "From:" . $from;
$message = "<html><body><head></head>";
$message .= "<h1>Hello, World!</h1>";
$message .= "</body></html>";
if(mail($to,$subject,$message,$headers)){
echo "Mail Sent.";
} else {
echo 'failed';
}
?>
Thats because PHP does not make new lines by it self. You can use echo "Lalala \n" to make new lines.
I know there are a few similar questions to this but I just can't get it working.
Ok, I have a list of emails grabbed from my database in a variable called $emailList.
I can get my code to send an email from a form if I put the variable in the $to section but
I cannot get it to work with bcc. I've even added an email to the $to incase it was that but it doesn't make a difference.
Here is my code.
$to = "name#mydomain.com";
$subject .= "".$emailSubject."";
$headers .= 'Bcc: $emailList';
$headers = "From: no-reply#thepartyfinder.co.uk\r\n" . "X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}
I've tried both codes:
$headers .= 'Bcc: $emailList';
and
$headers .= 'Bcc: '.$emailList.';
It's not that the emails aren't separated because they are. I know they are because it works if I put $emailList in the $to section.
I Should add, ignore the $message bits and the HTML stuff. I've not provided all of that so that is why it's missing from this code.
You have $headers .= '...'; followed by $headers = '...';; the second line is overwriting the first.
Just put the $headers .= "Bcc: $emailList\r\n"; say after the Content-type line and it should be fine.
On a side note, the To is generally required; mail servers might mark your message as spam otherwise.
$headers = "From: no-reply#thepartyfinder.co.uk\r\n" .
"X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Bcc: $emailList\r\n";
You were setting BCC but then overwriting the variable with the FROM
$to = "name#mydomain.com";
$subject .= "".$emailSubject."";
$headers .= "Bcc: ".$emailList."\r\n";
$headers .= "From: no-reply#thepartyfinder.co.uk\r\n" .
"X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}