This question already has answers here:
PHP mail: All emails are received in the SPAM folder [closed]
(4 answers)
Closed 8 years ago.
this is the mail body header subject and message
$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= "Content-Type: text/html" . PHP_EOL;
$headers .= "From: domin name" . PHP_EOL;
$subject = "1+1 Weekend Bonanza from Pizza Hut";
$message = "";
$message .= '<html>
message body
</html>';
*this is the mail function which i'm using.
mail($to, $subject, $message, $headers);*
My mail always go in the spam folder help me to send it in the inbox as it is very important to send them in the inbox pleae help me out.
Thanks for help in advance.
I'm unable to post the image as my reputation is low. in place of image i have written their is a image.
Email usually arrives to span because of bad headers. Try looking here.
<?php
$headers .= "Organization: Sender Organization\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n"
?>
This additional headers for ur emails might help you
$subject = "1+1 Weekend Bonanza from Pizza Hut";
$header = "from: domin name \r"."<br >";
$header .= "Content-Type: text/html; charset=ISO-8859-1 \r"."<br >";
$header .= "Return-Path: <mail#domainname.com> \r"."<br >";
$header .= "X-Priority: 1 (Highest) \r"."<br >";
$header .= "X-MSMail-Priority: High \r"."<br >";
$header .= "Importance: High \r"."<br >";
$header .= "MIME-Version: 1.0 \r"."<br >";
$message = "<html>
<head>
<meta http-equiv='content-type' content='text/html;charset=UTF-8' />
//Add more here
Related
I have a website contact form that sends HTML email with photo attachments as an email to Iphone mail application. I am receiving the following error message on my Iphone:
"This message cannot be displayed because of the way it is formatted. Ask the sender to send it again using a different format or email program. multipart/mixed".
Is this has something to do with email content-type and how to fix it in my PHP code.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$sender_email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
$body = "--$boundary\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($message_body));
$sentMail = mail($recipient_email, $subject, $body, $headers);
This question already has answers here:
How to send UTF-8 email?
(3 answers)
Closed 5 years ago.
I have the following PHP code:
<?php
$to = 'info#neatgr.cf';
$subject = date("d/m/Y");
$message = 'Hey 123 !## αβγ';
$headers = "From: testsite < mail#testsite.com >\n";
$headers .= "Cc: testsite < mail#testsite.com >\n";
$headers .= "X-Sender: testsite < mail#testsite.com >\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: mail#testsite.com\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
mail($to,$subject,$message,$headers);
echo "<script type='text/javascript'>alert('Message sent! We will get back to you soon!');</script>";
echo "<script>window.location.href = 'http://example.com';</script>";
?>
The mail gets sent fine. The problem is that αβγ (Unicode Characters) doesn't get on the mail recipient's end correctly.
This is what the recipient sees: Hey 123 !## αβγ
This is what he should see: Hey 123 !## αβγ
I've looked everywhere and tried everything, changing headers, converting my string to unicode etc. etc., but nothing has worked. Maybe I'm doing something wrong?
Use the UTF-8 charset header, for example:
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
Goes to:
$headers .= "Content-Type: text/html; charset=UTF-8\n";
I have a contact form that generates an email. If the customer has an Hotmail account (that I put in the Reply-To part of the header) then the email is not sent, any other email address is fine and the email sends without a problem.
For example:
if $contactEmail is mail#hotmail.com the email is not sent.
if $contactEmail is mail#site.com the email is sent.
Here is my Header ...
$headers = "From: My Site <info#mysite.com>\r\n";
$headers .= "X-Sender: <info#mysite.com>\r\n";
$headers .= "Reply-To: $contactEmail\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Mailer: PHP4\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "Return-Path: <info#mysite.com>\r\n";
Any thoughts/advice please?
Thanks.
As per the PHP manual regarding sending HTML mail, try adding the "to" header:
$headers = "From: My Site <info#mysite.com>\r\n";
$headers .= "To: Whoever <whoever#othersite.com>\r\n";
$headers .= "X-Sender: <info#mysite.com>\r\n";
$headers .= "Reply-To: $contactEmail\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Mailer: PHP4\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "Return-Path: <info#mysite.com>\r\n";
Try jerdiggity's answer first and check if the mail ends in the junk folder. Microsoft's SmartScreen spam technology is very hard to come by. You have to create an DNS SPF record and “un-junk” some mails in order to get your IP whitelisted.
I was testing a PHP Form for my client, when I realized that file attachment wasn´t optional, I have the full code here (it´s pretty long). Form works fine, but if you don´t choose any file, the e-mail will never arrive to it´s destination. I want to send the mail anyway and receive it without the attach.
I´m using PHP and jForm for validation.
Here is the input tag for file attaching (there to many input tags at the form.php file to list them here)
<input type="file" name="adjunto" id="adjunto">
And here is the send.php file (the true form is too long to publish here, i´m writing a shorter version of it)
<?php
// THE USER CHOOSES FROM A JOB LIST
$busqueda = $_POST["busqueda-list"];
$cargo = $_POST["cargo-list"];
// FILLS PERSONAL INFORMATION
$nombre = $_POST["nombre"];
$apellido = $_POST["apellido"];
$sexo = $_POST["sexo-list"];
// WE STYLE A MESSAGE WITH LOTS OF INPUTS
$mensaje = 'In the real form here is a table with lots of input styled';
// AND THEN WE ATTACH (in spanish spells adjunto)
$adjunto_name=$_FILES["adjunto"]["name"];
$adjunto_type=$_FILES["adjunto"]["type"];
$adjunto_size=$_FILES["adjunto"]["size"];
$adjunto_temp=$_FILES["adjunto"]["tmp_name"];
// IF THERE IS A FILE ATTACHED
if (is_uploaded_file($adjunto_temp))
{if($adjunto_type=="application/octet-stream" or $adjunto_type=="text/plain" or $adjunto_type=="application/msword" or $adjunto_type=="application/vnd.openxmlformats-officedocument.wordprocessingml.document" or $adjunto_type=="application/pdf" )
{
// MEET THE HEADERS
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: ".$email."\n";
// MAIL HEADERS with attachment
$fp = fopen($adjunto_temp, "rb");
$file = fread($fp, $adjunto_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
// Normal headers
$headers = "From: ".$email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".gettimeofday()." TheSystem#".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With mensaje
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$mensaje."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$adjunto_type." ";
$headers .= "name=\"".$adjunto_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$adjunto_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
// WE SEND MAIL WITH HEADERS
#mail("name#example.com", "".$busqueda." ".$cargo."", $mensaje, $headers);
fclose($fp);
}
// IF NOT, JUST SEND MAIL
else
#mail("ezemosho#gmail.com", "".$busqueda." ".$cargo."", $mensaje);
}
?>
Please I need a hand with this, I´m doing my best (i´ve already search here and other forums) and I think this maybe a problem many people had before!
Thank you!
you need to give one more condition on top
if (is_uploaded_file($adjunto_temp)) {
if($adjunto_type=="application/octet-stream" or $adjunto_type=="text/plain" or $adjunto_type=="application/msword" or $adjunto_type=="application/vnd.openxmlformats-officedocument.wordprocessingml.document" or $adjunto_type=="application/pdf" )
{
........... // your other stuff with respect to headers
#mail("name#example.com", "".$busqueda." ".$cargo."", $mensaje, $headers);
}
}
else
#mail("name#example.com", "".$busqueda." ".$cargo."", $mensaje);
now the mail will go on both conditions.
UPDATED WITH YOUR CODE
if (is_uploaded_file($adjunto_temp))
{
if($adjunto_type=="application/octet-stream" or $adjunto_type=="text/plain" or $adjunto_type=="application/msword" or $adjunto_type=="application/vnd.openxmlformats-officedocument.wordprocessingml.document" or $adjunto_type=="application/pdf" )
{
// MEET THE HEADERS
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: ".$email."\n";
// MAIL HEADERS with attachment
$fp = fopen($adjunto_temp, "rb");
$file = fread($fp, $adjunto_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
// Normal headers
$headers = "From: ".$email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".gettimeofday()." TheSystem#".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With mensaje
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$mensaje."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$adjunto_type." ";
$headers .= "name=\"".$adjunto_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$adjunto_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
// WE SEND MAIL WITH HEADERS
#mail("name#example.com", "".$busqueda." ".$cargo."", $mensaje, $headers);
fclose($fp);
}
}
// IF NOT, JUST SEND MAIL
else
{
// MAIL HEADERS
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: ".$email."\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".gettimeofday()." TheSystem#".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
#mail("ezemosho#gmail.com", "".$busqueda." ".$cargo."", $mensaje);
}
Put the else statement for your first if condition, in your code you are using else for the condition2.
if (condition1) {
if (condition2) {
.........
.........
}
} else {
}
i'm using following code to send confirmation mail, but i dont know why the url parameter in mail removed
and in mail i'm getting url like http://example.com/confirm.php?user_id= parameter value (1) is being removed
$headers = "From: admin#example.com \n";
$headers .= "X-Mailer: PHP/SimpleModalContactForm";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: quoted-printable\n";
$subject = "Confirm Your Registration Example.com";
$subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");
$to="abc#demo.com";
$body="<table> <tr> <td> Hello </td> </tr>";
$body.="<tr> <td> Please confirm your registration by clicking following link <td> </tr>";
$body.="<tr> <td> http://example.com/confirm.php?user_id=1</td> </tr>";
$body.="</table>";
#mail($to, $subject, $body, $headers) or die("Unfortunately, a server issue prevented delivery of your message.");
Did you try with a tag like
http://example.com/confirm.php?user_id=1
solved,
just changed headers from
$headers = "From: admin#example.com \n";
$headers .= "X-Mailer: PHP/SimpleModalContactForm";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: quoted-printable\n";
to
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: admin#example.com' . "\r\n";