Is there a better way (than adding headers such as below) for PHP webforms to be sent directly to inbox and not to junk/spam folders.
$to = $email;
$subject = 'subject here';
$headers = "From: "."emailaddress"."\r\n";
$headers .= "MIME-Version: 1.0 \r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1 \r\n";
Thank you!
PS. I have access to the Mail Server and Domain(DNS).
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
i want to send a mail the code is given below. i cant understand waht is happening . It works on localhost but not on live server.
if (isset($_POST['test_mail'])){
$to = '2606ankit#gmail.com'; //put email address on which mail send
$subject = "Newsletter"; //Put subject of mail here
$from = 'ankit#studiokrew.com'; //put email address from
//email body start
// $body .= file_get_contents('file/'.$filename.'');
$body .= 'anio';
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: '.$from. "\r\n";
//if you need to send cc mail then uncomment below line and change email address
//$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$body,$headers);
}
try this..
<?php if (isset($_POST['test_mail'])){
$host=$_SERVER['HTTP_HOST'];
$replyto="<no-reply >";
$to ='2606ankit#gmail.com';
$subject = "Newsletter";
$from = 'ankit#studiokrew.com';
$headers = "From: \"Invoice\"<noreply#$host>\n";
$headers .= "Reply-To: ".$replyto."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"abc"\"\r\n\r\n";
$headers .= 'From: '.$from. "\r\n";
$header .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
$body = "This is a multi-part message in MIME format.\r\n";
$body .= "Content-type:text/html; charset=iso-8859-1\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= 'anio';
mail($to,$subject,$body,$headers);
}
?>
check the MTA logs on your server.also web server logs the answer will be there somewhere.
Test with a simple mail() script that does not require any external data, just to make sure that your server indeed can send mail. If that fails, you'd have to contact the server admins for help.
When i am sending UTF-8 email using mail() from my site . Gmail showing it very nice but outlook showing it like this یب سائٹ Ù
my code is
$to = "xxx#gmail.com";
$subject ="Subject";
$headers = "From: xxxx \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset:UTF-8 \r\n";
$message = "email message";
mail ($to,$subject,$message,$headers);
You might want to add encoding to your subject
$subject='==?UTF-8?Q?Subject?='
and/or a Content-Transfer-Header
$headers.='Content-Transfer-Encoding: quoted-printable'
depending on the message part the encoding problem shows.
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"];
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.
I have an HTML email needed to be sent to more than one person:
$mem = "abc#def.com, qwr#rty.com";
$subject = 'Invitation to Party';
$headers = "From: info#example.com\r\n";
$headers .= "Reply-To: info#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "SNIPPED";
mail($mem, $subject, $message, $headers);
It is sending to the first email which is abc#def.com, but it's not sending mail for the second recipient which is qwr#rty.com and the rest.
The email addresses are examples.
Is there any work-around for this besides using library?
you may send the second id as a bcc,
$headers .= "Bcc: ".$bcc."\r\n";