I have a 15 letter code that seems to add itself at the end of emails I send.
This code seems to change every email batch I send (if I send multiple emails via a loop, they all have the same code, but next time I send multiple emais, the code is different) and the code always seem to be 15 characters.
So does anybody know where this code might be coming from, and how to prevent it?
I'm using the default PHP mail() function.
Edit:
Heres a snippet of the code generating the Email.
$boundary = uniqid('np');
$headers = 'From: This.Site <no-reply#This.Site>' . "\r\n" .
'Reply-To: no-reply#This.Site' . "\r\n" .
"MIME-Version: 1.0" . "\r\n" .
"Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n".
'X-Mailer: PHP/' . phpversion();
mail($email, 'Subject - '.$title.' - Client Name', create_notif_email($name, $compagnieFrom, $title, $link, $boundary), $headers);
function create_notif_email($name, $compagnieFrom, $title, $link, $boundary){
$urlSite = get_bloginfo('url');
$html = '';
$html .= file_get_contents(__DIR__.'/plaintext.txt');
$html .= "\r\n\r\n--" . $boundary . "\r\n";
$html .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
$html .= file_get_contents(__DIR__.'/plaintext.txt');
$html .= "\r\n\r\n--" . $boundary . "\r\n";
$html .= "Content-type: text/html;charset=utf-8\r\n\r\n";
$html .= file_get_contents(__DIR__.'/mail.html');
$html .= $boundary;
$html = str_replace('[NOM]', $name, $html);
$html = str_replace('[FROM]', $compagnieFrom, $html);
$html = str_replace('[TITLE]', $title, $html);
$html = str_replace('[LINK]', ''.$link.'', $html);
$html = str_replace('[URLSITE]', $urlSite, $html);
return $html;
}
mail.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Nouveau poste pour vous! - [TITLE] - Bestaff</title>
</head>
<body style="width:100%; margin:0; padding:0; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;">
<!-- body wrapper -->
<table cellpadding="0" cellspacing="0" border="0" style="margin:0; padding:0; width:100%; line-height: 100% !important;">
<tr>
<td valign="top">
<!-- edge wrapper -->
<!-- ///////////////////////////////////////////////////// -->
<table cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td width="20"></td>
<td valign="top" style="vertical-align: top; text-align:left;">
<br /><img src="[URLSITE]/images/image.png" alt="Bestaff.in" title="Bestaff.in"/><br />
<div style="font-family:Arial, sans-serif; font-size:14px; line-height:18px;">
<br /><i>English version follows</i><br /><br />
Bonjour [NOM],<br /><br />
[FROM] [TITLE].<br /><br />
[LINK]<br /><br />
Bonne chance!<br /></br>
<i style="font-style=12px"></i>
<br /> <hr /><br />
Hello [NOM],<br /><br />
[FROM][TITLE].<br /><br />
[LINK]<br /><br />
Good luck!<br /></br>
<i style="font-style=12px"></a></i><br />
</div>
</td>
<td width="20"></td>
</tr>
</table>
</td>
</tr>
</table>
<!-- / page wrapper -->
</body>
</html>
and plaintext.txt
English version follows
Bonjour [NOM],
[FROM][TITLE].
[LINK]
Bonne chance!
Hello [NOM],
[FROM][TITLE].
[LINK]
Good luck!
Boundary id typically start with double dash and are followed immediatly by a line break
Try this....
Change
$html .= $boundary;
to
$html .= '--'.$boundary.'
';
source:https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
Related
The below code gives the output as how in screenshot. I want to send this content via php mail function . When i try to add this code into $message , It doesnt work as it contains php code(to retrieve data from table) in between html code. Kindly help on how this can be achieved ?
This is the code i was trying out for email .
<?php
include('db.php'); //connection to database
$to = 'example#gmail.com';
$subject = "test php mail" ;
$message = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta charset="utf-8">
<title> Fetching data </title>
</head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th{
color:#DC143C;
}
td {
color:#0000FF;
}
</style>
<body>
<font size="4" face="Courier New" >
<table border="1" style="width:50%" align="center">
<tr bgcolor="#2ECCFA">
<th style="padding: 20px" bgcolor="#E6E6FA"
color="#DC143C" color="red">Word of the Day</th>
</tr>
<!-- I used while loop to fetch data and display rows of date on html
table -->
<?php
$records = mysql_query("SELECT * FROM hindiday order by
rand(curdate())
limit 1 ");
while ($course = mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$course['hindiword'] . ' ' .$course['phonetic'] . ' '
.$course['id']." </td>"; "</tr>" ;
}
?>
</table>
</body>
</html> ' ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: abc#gmail.com.com>' . "\r\n";
// Send email
if(mail($to,$subject,$message,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
I would suggest looping outside the string, and the concatenate the result like so :
$string = ''; // The variable used to contain your data
$records = mysql_Something is wrong("SELECT * FROM hindiday order by rand(curdate()) limit 1 ");
while ($course = mysql_fetch_assoc($records)){
//Filling that variable
$string .= "<tr>";
$string .= "<td>".$course['hindiword'] . ' ' .$course['phonetic'] . ' ' .$course['id']." </td>"; "</tr>" ;
}
//Using the variable in your message
$message = '
...
'. $string .'
...
';
That way wherever you want to add the $string you just concatenate it, as if you try to execute PHP code inside a string it'll be considered as a string and the PHP in question won't be executed.
So the final result would look like this :
<?php
include('db.php'); //connection to database
$to = 'example#gmail.com';
$subject = "test php mail" ;
$string = ''; // The variable used to contain your data
$records = mysql_Something is wrong("SELECT * FROM hindiday order by rand(curdate()) limit 1 ");
while ($course = mysql_fetch_assoc($records)){
//Filling that variable
$string .= "<tr>";
$string .= "<td>".$course['hindiword'] . ' ' .$course['phonetic'] . ' ' .$course['id']." </td>"; "</tr>" ;
}
$message = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta charset="utf-8">
<title> Fetching data </title>
</head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th{
color:#DC143C;
}
td {
color:#0000FF;
}
</style>
<body>
<font size="4" face="Courier New" >
<table border="1" style="width:50%" align="center">
<tr bgcolor="#2ECCFA">
<th style="padding: 20px" bgcolor="#E6E6FA"
color="#DC143C" color="red">Word of the Day</th>
</tr>
<!-- I used while loop to fetch data and display rows of date on html
table -->
'. $string .'
</table>
</body>
</html> ' ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: abc#gmail.com.com>' . "\r\n";
// Send email
if(mail($to,$subject,$message,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
I am trying to embed the image to the html content of email in php but whenever the email sent it show me broken link of image there. Image is not embeding to the email here is the code
<?php
$to = 'xxxx#xxxx.com';
$subject = "Beautiful HTML Email using PHP by CodexWorld";
$htmlContent = '
<html>
<head>
<title>Welcome to CodexWorld</title>
</head>
<body>
<h1>Thanks you for joining with us!</h1>
<table cellspacing="0" style="border: 2px dashed #FB4314; width: 300px; height: 200px;">
<tr>
<th>Name:</th><td>CodexWorld</td>
</tr>
<tr style="background-color: #e0e0e0;">
<th>Email:</th><td>contact#codexworld.com</td>
</tr>
<tr>
<th>Website:</th><td>www.codexworld.com</td>
</tr>
<tr>
<th>image:</th><td><img src="http://xxxxxxxxxxxxx.com/email/1.png"/></td>
</tr>
</table>
</body>
</html>';
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: xxxx#xxxxx.com' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
Please guide me where is I am wrong
When I try to send my mail via php, GMail does not accept my html:
Simple example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body style="padding:0px; margin:0PX;" bgcolor="#dfdfdf">
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="" style="table-layout:fixed; margin:0 auto;">
<tr>
<td width="640" align="center" valign="top">
Screenshot: <img src="data:image/jpeg;base64,someimginfo" />
</td>
</tr>
</table>
</body>
</html>
GMail output:
Gmail edits my text e.g. <html> --> "<html>"
The headers I use: MIME-Version: 1.0 & Content-type: text/html; charset=UTF-8
What am I doing wrong?
EDIT PHP Code:
<?php
$recipient = "xxxxxx#gmail.com";
$image = $_POST["image"];
$contact = $_POST["contact"];
$token = $_POST["token"];
if($token != "***"){
exit('{"success":false, "error":"Invalid Token"}');
}
$from = (filter_var($contact, FILTER_VALIDATE_EMAIL)) ? $contact : 'no- reply#example.com';
$header = 'From: webmaster#example.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$txt = '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body style="padding:0px; margin:0PX;" bgcolor="#dfdfdf">
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="" style="table-layout:fixed; margin:0 auto;">
<tr>
<td width="640" align="center" valign="top">
Screenshot: <img src="data:image/jpeg;base64,' . $image . '" />
</td>
</tr>
</table>
</body>
</html>
';
if(mail($recipient, "APP Support request", $txt, $header)){
exit('{"success":true}');
}
exit('{"success":false, "image":"' . $image . '"}');
?>
PHPmailer is the best class for the job!
https://github.com/PHPMailer/PHPMailer
Edit: replaced http://phpmailer.worxware.com/ with the github address.
It looks like the problem is in these lines:
$header = 'From: webmaster#example.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// …
if(mail($recipient, "APP Support request", $txt, $header)){
You switch between the names $header and $headers. So when you add the text/html content type to the variable $headers, that isn’t affecting the $header variable that is being used to actually send the email.
You should switch all those variables to the same name, $headers.
This question already has answers here:
Send HTML in email via PHP
(8 answers)
Closed 7 years ago.
I am setting up a confirmation email script for our customers to receive an email when they complete the online form. I uploaded my script and tested but I received an email with just the raw HTML. I have been looking at some tutorials trying to do this as well. I validated my HTML and I passed all the tests. Is there something that I have to include in my PHP for my body string to be interpreted as HTML?
Here is my script
<?php
//Script for sending a confirmation email
$body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
<title>Demystifying Email Design</title>
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>
</head>
<body style=\"margin: 0; padding: 0; background-color: #ecf0f1;\">
<table cellpadding=\"0\" cellspacing=\"0\" width=\"60%\" align=\"center\" style=\"border: 1px solid #bdc3c7;\">
<tr bgcolor=\"#3498db\">
<td align=\"center\">
<img alt=\"Logo\" src=\"http://www.****.com/logo-lg.jpg\" style=\"width: 50%; height: auto; padding-top: 5%; padding-bottom: 5%;\" />
</td>
</tr>
<tr bgcolor=\"#ffffff\" align=\"center\">
<td>
<h3 style=\"padding-top: 5%; padding-bottom: 5%;\">Worldwide innovator in flexible liquid packaging</h3>
</td>
</tr>
<tr align=\"center\" bgcolor=\"#ffffff\">
<td>
<h4 style=\"padding-top: 5%; padding-bottom: 5%;\">Thank you for contacting customer service. We've received your sample request; one of our team members will be in contact with you in the very near future. Thanks again for your time and interest.</h4>
</td>
</tr>
</table>
</body>
</html>";
$to = "*******#****.com";
$subject = "Thanks for Reaching out";
if (mail($to,$subject,$body)){
echo "Mail was sent";
} else{
echo "Failed";
}
This is the email I received
You need to also set a header indicating this is HTML, e.g.
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
Source (see Example 3).
Correct code will be:
$to = "*******#****.com";
$subject = "Thanks for Reaching out";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
if (mail($to,$subject,$body,$headers)){
echo "Mail was sent";
}
I am trying to insert and send email with html body but the received email is pure html text.I've added correct headers but seems that they not helping me ( or at least I think are correct one ).
Here is the code
if(isset($_POST['email'])) {
$email_to = "";
$email_subject = "";
$firstname = $_POST['name']; // required
$email = $_POST['email']; // required
$message = $_POST['message']; // not required
$phone = $_POST['phone'];
$captcha = $_POST['captcha'];
$subject = $_POST['subject']; // required
$email_message = "New email:\n\n";
$email_message .= '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="top" bgcolor="#838383" style="background-color:#838383;"><br>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"><img src="images/top.png" width="600" height="177" style="display:block;"></td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#d3be6c" style="background-color:#d3be6c; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000000; padding:0px 15px 10px 15px;">
<div style="font-size:24px; color:#555100;"><br>
'.$firstname.'
</div><br>
<div>'.$subject.'</div>
<div>
'.$message.'
'.$email.'
'.$phone.'
</div></td>
</tr>
<tr>
<td align="left" valign="top"><img src="images/bot.png" width="600" height="18" style="display:block;"></td>
</tr>
</table>
<br>
<br></td>
</tr>
</table>
</body>
</html>';
// create email headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
}
http://pastebin.com/5aQh0Gvz
You were resetting $headers when setting the From: header:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n". // << note the dot before = that wasn't here before making `$headers` to be resetted
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();