PHP email message not working with HTML - php

Trying to get my form to email working, but when I add this part of the code
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
the email won't send. When I remove it, the email sends, but all the tags show up. Any idea what the problem is?
My php code is below:
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$injury = $_POST['injury'];
$message = $_POST['message'];
$myemail = 'example#gmail.com';
$subject = 'Brain Damage Info Free Evaluation Form';
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$email_message = '<html><body>';
$email_message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$email_message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$email_message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$email_message .= "<tr><td><strong>Phone:</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>";
$email_message .= "<tr><td><strong>Injury:</strong> </td><td>" . strip_tags($_POST['injury']) . "</td></tr>";
$email_message .= "<tr><td><strong>Description of Injury:</strong> </td><td>" . $_POST['message'] . "</td></tr>";
$email_message .= "</table>";
$email_message .= "</body></html>";
$sent = mail($myemail,$subject,$email_message,$headers);

I use
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
with this i do not get such errors. I think the charset is the problem.

Related

Mail going to inbox but cannot display sender name

I want to send to mail to user for any update.
My first tried as below, here all mail goes to spam folder but here sender name display well.
This code is
$headers = "From: Sender Name <info#senderweb.com >\r\n" .
"Reply-To: info# senderweb.com\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
After prevent goes to spam folder, my below code make all mail goes well at inbox but here sender name display server name something like senderwe#server1.server.com.
I found this report at track delivary of cpanel : ECDHE-RSA-AES128-GCM-SHA256:128 CV=yes: SMTP error from remote mail server after MAIL FROM:< senderwe#server1.server.com > SIZE=3829: 553 5.7.1 [BL21] Connections will not be accepted from ###.72.###.129, because the ip is in Spamhaus's list; s
$headers = "From: Sender Name <info#senderweb.com >";
$headers = "Reply-To: info# senderweb.com \r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
I also look at Spamhaus's list by this ip, where I found my ip is listed in the XBL.
Please where is my problem here to display sender name at inbox?
Full Code:
$subject = "My subject";
$message .= "<html>";
$message .= "<head>";
$message .= "<style type=\"text/css\" media=\"screen\">";
$message .= "a:link, a:visited {color:#A0C804; text-decoration:none;}";
$message .= "a:hover {color:#339933; text-decoration:none;}";
$message .= "body {background-color:#FFFFFF;";
$message .= "font-family:Arial, Helvetica, sans-serif;";
$message .= "color:#000000;";
$message .= "font-size:12px;}";
$message .= "p.general {font-size: 14px;";
$message .= "line-height: 16px;";
$message .= "font-weight: normal;";
$message .= "padding-right:20px;";
$message .= "padding-left:17px;";
$message .= "margin-bottom:3px;}";
$message .= ".page {background-color:#ff0000;";
$message .= "padding:0px;";
$message .= "width:100%;}";
$message .= ".content {width:100%;";
$message .= "height:auto;";
$message .= "background-color:#FFFFFF;";
$message .= "padding:10px;";
$message .= "border:#ECEBEB;}";
$message .= "span.prospan {font-size: 14px;";
$message .= "line-height: 16px;";
$message .= "padding-left:20px;";
$message .= "margin-bottom:10px;}";
$message .= "p.proitem {font-size: 14px;";
$message .= "margin-bottom:10px;";
$message .= "padding-left:17px;}";
$message .= "p.tota {color: #ff0000;";
$message .= "padding-left:17px;";
$message .= "font-size: 14px;";
$message .= "margin-bottom:20px;";
$message .= "font-weight: bold;}";
$message .= "p.soong {color: #000000;";
$message .= "padding-left:17px;";
$message .= "margin-bottom:10px;";
$message .= "font-size: 14px;";
$message .= "font-weight: bold;}";
$message .= "p.foot {color: #000000;";
$message .= "margin-bottom:10px;";
$message .= "padding-left:17px;";
$message .= "font-size: 14px;}";
$message .= "</style>";
$message .= "<body>";
$message .= "<div class=\"page\">";
$message .= "<div class=\"content\">";
$message .= "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#ECEBEB\">";
$message .= "<tr>";
$message .= "<td style=\"text-align:left;\" bgcolor=\"#FF6699\"><img src=\"http://www.myweb.com.au/images/logo.png\" width=\"99\" height=\"83\" style=\"padding:15px;\" /></td>";
$message .= "<td style=\"text-align:right;\" bgcolor=\"#FF6699\"><h2 style=\"color:#ffffff;padding:20px;\" >Web name</h2></td>";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td width=\"100%\" cellpadding=\"20\" align=\"left\"><br>";
$message .= "<p class=\"general\"><b>Congratulation ! </b></p><br>";
$message .= "<p class=\"general\">Dear <b>".$my_name."</b> ,</p><br>";
$message .= "<p class=\"general\">Massage to clint.</p><br>";
$message .= "</td>";
$message .= "</tr>";
$message .= "</table>";
$message .= "</div>";
$message .= "</div>";
$message .= "</body>";
$message .= "</html>";
$headers = "From: Sender Name <info#senderweb.com >";
$headers = "Reply-To: info#senderweb.com \r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
mail($email,$subject,$message,$headers);
Send a delist request for sender address. Any local cPanel user can use the 127.0.0.1 IP address to send mail without authentication. This can make it difficult for system administrators to determine which cPanel account sent the mail, especially when a malicious user spoofs an email address to disguise the origin of the email.
To require cPanel & WHM to put the actual sender in the header, enable the Experimental: Rewrite From: header to match actual sender option in WHM's Exim Configuration Manager interface (Home >> Exim Service Configuration >> Exim Configuration Manager). Check here https://documentation.cpanel.net/display/CKB/How+to+Prevent+Email+Abuse

Include Variables in PHP mail command

I'm sure I'm wrong about something basic, but can not find where the error is. I will appreciate your help.
I have a php page with a single 4 fields contact form.
I need send the name and email as variable, so i can see it properly when email is received.
IT WORKS - BUT DONT SEND NAME AND EMAIL AS VARIABLE:
All messages arrives as "no-reply#luchodomain.com" and doesnt look professional (and can't do reply from my outlook)
if ($_POST) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: no-reply#luchodomain.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 .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
}
IT DOENST WORKS (but have the format and variables as i need)
I would like receive the messages like is normal Name, so i can do a quick reply. -This code don't send email, doesn't work-
if ($_POST) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
}
I will appreciate your help with this "headers" issue!
Thank you.
Make sure that you are receiving data in your post array. Make sure your form action. You have declared $message variable to blank after assigning the post value in it before. That's not a good trick enough. Please check updated code and let me know.
if ($_POST) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$subject = strip_tags($_POST['subject']);
$message = strip_tags($_POST['message']);
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//$message = "";
//$message .= '';
$message .= "\r\nName: " . $name . "";
$message .= "Email: " . $email . "\r\n";
$message .= "Subject: " . $subject . "\r\n";
$message .= "Message: " . $message . "";
//$message .= "";
//$message .= "";
mail($to,$subject,$message,$headers);
}
$to = 'pawanvikasitha2001#gmail.com, aravindasamapath87#gmail.com'; $subject = 'NEW ORDER HAS PLACED'; $message = "$name"; mail ($to,$subject,$message);
When you use the double quotes, You can simply add variables to it. Look at the $message

PHP: Why email not support html

I try to send an email from my web site, I received email but not support HTML.
Here is my code:-
////////
$headers = "From: $email\n" . "Reply-To: $email\n";
$headers .= "Register: Super market\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
//$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Register in Super market";
$email_to = EMAIL;
$emailMessage = "<b>NO :</b> " . $aid."\n";
$emailMessage .= "<b>Name :</b> " . $firstname.' '.$fathername.' '.$familyname. "\n";
$emailMessage .= "<b>Tell :</b> " . $tell . "\n\n";
$emailMessage .= "<b>Fax :</b> " . $fax . "\n\n";
$emailMessage .= "<b>Email :</b> " . $email . "\n\n";
//use php's mail function to send the email
#mail($email_to, $subject ,$emailMessage ,$headers );
Update:
Hi every one.
I set an question here and solved successful
But now i need to add some file as attachment.
So, I have 2 variable, That save the file upload into DB like this:-
$filenameword
$filenamezip
How can set this tow variable as file attachment in email inbox.
////////
$headers = "From: $email\n" . "Reply-To: $email\n"; // See the s at the end of $headers
$headers .= "Register: Super market\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
//$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Register in Super market";
$email_to = EMAIL;
$emailMessage = "<b>NO :</b> " . $aid."\n";
$emailMessage .= "<b>Name :</b> " . $firstname.' '.$fathername.' '.$familyname. "\n";
$emailMessage .= "<b>Tell :</b> " . $tell . "\n\n";
$emailMessage .= "<b>Fax :</b> " . $fax . "\n\n";
$emailMessage .= "<b>Email :</b> " . $email . "\n\n";
//use php's mail function to send the email
mail($email_to, $subject ,$emailMessage ,$headers );
You have a typo in your code.
You are assigning header strings to $headers but you're passing $header to the mail function.
Also please no # before functions. It's a bad practice.
////////
$headers = "From: $email\n" . "Reply-To: $email\n"; // See the s at the end of $headers
$headers .= "Register: Super market\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
//$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Register in Super market";
$email_to = EMAIL;
$emailMessage = "<b>NO :</b> " . $aid."\n";
$emailMessage .= "<b>Name :</b> " . $firstname.' '.$fathername.' '.$familyname. "\n";
$emailMessage .= "<b>Tell :</b> " . $tell . "\n\n";
$emailMessage .= "<b>Fax :</b> " . $fax . "\n\n";
$emailMessage .= "<b>Email :</b> " . $email . "\n\n";
//use php's mail function to send the email
mail($email_to, $subject ,$emailMessage ,$headers ); // See the s at the end of $headers

Why is PHP's mail() sending me dozens of blank emails?

I'm using PHP's mail() function within a WordPress theme to send form submissions to my email.
However, mail() has automatically sent me at least 20 blank emails,
within the last five minutes, without being submitted.
Could someone shed some light on what I've done to create this situation?
Here is the code from my (functions.php file)
function send_my_form(){
$form = array();
$form['fstname'] = $_POST['fstname'];
$form['lstname'] = $_POST['lstname'];
$form['email'] = $_POST['email'];
$form['message'] = $_POST['message'];
$send_to = 'fakeemail#gmail.com';
$subject = 'You\'ve recieved an email from' . $form['fstname'] . $form['fstname'];
$return = "-f" . $send_to;
$message = "First Name: " . $form['fstname'] . "\r\n";
$message .= "Last Name: " . $form['lstname'] . "\r\n";
$message .= "Email: " . $form['email'] . "\r\n";
$message .= "Message: " . $form['message'] . "\r\n";
$headers = 'MIME-Version: 1.0' . '\r\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
$headers .= 'From: ' . $send_to . '\r\n';
$headers .= 'Reply-To: ' . $form['email'] . '\r\n';
$headers .= 'Return-Path: ' . $send_to . '\r\n';
$headers .= '\r\nX-Mailer: PHP/' . phpversion();
mail($send_to, $subject, $message, $headers, $return);
}
add_action('wp_head', 'send_my_form');
This is what I mean by running it in a conditional. Verify the fields are set before running the mail script.
function send_my_form(){
if(isset($_POST['fstname']) && isset($_POST['lstname']) && isset($_POST['email']) && isset($_POST['message']))
{
$form = array();
$form['fstname'] = $_POST['fstname'];
$form['lstname'] = $_POST['lstname'];
$form['email'] = $_POST['email'];
$form['message'] = $_POST['message'];
$send_to = 'fakeemail#gmail.com';
$subject = 'You\'ve recieved an email from' . $form['fstname'] . $form['fstname'];
$return = "-f" . $send_to;
$message = "First Name: " . $form['fstname'] . "\r\n";
$message .= "Last Name: " . $form['lstname'] . "\r\n";
$message .= "Email: " . $form['email'] . "\r\n";
$message .= "Message: " . $form['message'] . "\r\n";
$headers = 'MIME-Version: 1.0' . '\r\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
$headers .= 'From: ' . $send_to . '\r\n';
$headers .= 'Reply-To: ' . $form['email'] . '\r\n';
$headers .= 'Return-Path: ' . $send_to . '\r\n';
$headers .= '\r\nX-Mailer: PHP/' . phpversion();
mail($send_to, $subject, $message, $headers, $return);
}
}

php email not reading html

For some reason, the html fails to render in gmail, but renders in hotmail.
Its vital that gmail reads the html, so I wonder which changes I should make to this header.
$from = "info#email.co";
$headers = "From: bob at info.co <" .($from) . ">\n";
$headers .= "Reply-To: ".($from) . "\n";
$headers .= "Return-Path: ".($from) . "\n";;
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-Mailer: PHP". phpversion() ."\n";
The message starts of as:
$message = '<html><body>';
$message .= "<p>";
$message .= "Hi $clean_fullName, <br><br>";
$message .= " Well, I've looked at what you shared with me and I'm delighted to include my personal learning suggestions that I hope will help you achieve your startup goals.";
$message .= "<br><br>";
$message .= "If they aren't quite what you're looking for, I take criticism better than most Entrepreneur Wizards
so please let me know by responding to this email and I'll take another look for you.";
$message .= "<br><br>";
$message .= "
$message .="<br><br>Otherwise, happy learning!<br><br>";
$message .= "<b>Total Learning time: </b>";
// create an array of all the duration
$counter = array();
foreach($data as $item) {
// add each duration item to the array after every iteration
array_push($counter, "{$item['duration']}");
}
//record and display the result to the user
$message .= array_sum($counter);
$message .= " hours <br><br>";
foreach($data as $item) {
$message .= "<b>
&#10139<a style='color:#FF6400; text-decoration: none' href='{$item['link']}'>{$item['title']}</a></b><br>";
$message .= "Format: {$item['format']} <br>";
$message .= "Cost: ${$item['costs']} <br>";
$message .= "Estimated Duration: {$item['duration']} hours<br>";
$message .= "<br>";
}
$message .= " If you have any questions, do not hesitate to reach out to us. <br><br>";
$message .= "</p>";
$message .= '</body></html>';
mail
mail($to,$subject,$message,$headers);
I am still learning :)
but this should work
$from = "info#email.co";
$headers .= 'From: bob at info.co <$from>' . "\r\n";
$headers .= 'Reply-To: <$from> ' . "\r\n";
$headers .= 'Return-Path: <$from>' . "\r\n";
$headers .= 'MIME-Version: 1.0 ' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= 'X-Priority: 3' . "\r\n";
$headers .= 'X-Mailer: PHP". phpversion()' . "\r\n";
Answer from comments
$message = '<html><body>';
u should do like this
$message .= '<html>'. "\r\n";
$message .= '<body>' . "\r\n";
You have too much errors in writing missing dot semi etc
as i see your html tag wasn't open at all.
there is lot options to write this template
1.
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
2.
$message.= 'blasldl asdas d asdas' . "\r\n";
$message.= ' sdfadasdasd dsad' . "\r\n";
U can change "\r\n"with $rn = "\r\n"; and use it fast as $rn
$message.= 'blasldl asdas d asdas' . $rn;
$message.= ' sdfadasdasd dsad' . $rn;
u can try those solutions and tell me whats happening .
and dont place all email under<p></p>

Categories