Plain text version of email is not working - php

So I have the script sending a multipart email of plain text and html, some reason the plaintext version is not working, but I can see that it is sending when I show original in gmail. It just shows the html though when I click message garbled?
// headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= 'From: From Name <'. FROM_EMAIL. ">\r\n";
$headers .= 'To: '.$member->member_info['memem']. "\r\n";
$headers .= 'Bcc: receipts#gmail.com' . "\r\n";
$headers .= "Subject: Registration Receipt\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
// Additional headers
$message . "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
$message .= $receipt_txt;//plain text
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
$message .= $receipt_html;//html
$message .= "\r\n\r\n--" . $boundary . "--";
mail( $member->member_info['memem'], 'Registration Receipt', $message, $headers );

Crap. I found it. "$message . "\r\n\r\n--" . $boundary . "\r\n";" should be "$message .= "\r\n\r\n--" . $boundary . "\r\n";" I feel dumb :(

Related

how to send multipart/alternative email with PHP correctly

I'm trying to use the built-in PHP mail function to send multipart messages that contain a html and a plain text version of my message. I've been playing around with different encoding types but, I keep running into problems. Originally I set Content-Transfer-Encoding to Binary but, that resulted in exclamation points being placed every 78 characters. I also tried base64 but I believe that base64 is overkill for what I am doing.
All I'm doing is sending basic HTML, no encoded images, files, or attachments. I'd prefer an encoding method that would still allow the source code to be human readable.
I heard that Quoted-Printable is what I'm looking for but, when I attempted to send messages using that encoding type the result ending up looking really weird. I noticed a bunch of " symbols sprinkled throughout the message source code.
Here is the code I'm using:
$to = "to#test.com";
$subject = "test subject";
$boundary = uniqid('np');
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: from-address#test.com\r\n";
$headers .= "Reply-To: reply-address#test.com\r\n";
$headers .= "Return-Path: return-path#test.com\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/plain; charset=UTF-8\r\n";
$message .= "Content-Transfer-Encoding: Quoted-Printable\r\n";
$message .= $plainTextMessage;
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\r\n";
$message .= "Content-Transfer-Encoding: Quoted-Printable\r\n";
$message .= $HTMLmessage;
$message .= "\r\n\r\n--" . $boundary . "--";
$ok = mail($to,$subject,$message,$headers);
What the heck am I doing wrong here?
Hi try the following code,
$to = "to#test.com";
$subject = "test subject";
$plainTextMessage = "Hi all";
$HTMLmessage = "<b>Hi all</b>";
//$boundary = uniqid('np');
$boundary = md5(uniqid(time()));
$headers .= "From: from-address#test.com\r\n";
$headers .= "Reply-To: reply-address#test.com\r\n";
$headers .= "Return-Path: return-path#test.com\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/plain; charset=UTF-8\r\n";
$message .= "Content-Transfer-Encoding: Quoted-Printable\r\n";
$message .= $plainTextMessage;
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\r\n";
$message .= "Content-Transfer-Encoding: Quoted-Printable\r\n";
$message .= $HTMLmessage;
$message .= "\r\n\r\n--" . $boundary . "--";
$ok = mail($to,$subject,$message,$headers);
May it will help
No need for a third party library or an external mail forwarding host. This is what I use and it works like a charm. It also fixes some potential security holes by forcing headers using the $from address that can otherwise reveal your system user :
private function sendMail($to, $from, $fromName, $subject, $text, $html)
{
$boundary = uniqid('np');
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: ".$fromName." <".$from.">" . "\r\n";
$headers .= "X-Sender: ".$fromName." <".$from.">\n";
$headers .= "Return-Path: <".$from.">\n";
$headers .= "To: ".$to."\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
// Content body
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
// Plain text body
$message .= $text;
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
// Html body
$message .= $html;
$message .= "\r\n\r\n--" . $boundary . "--";
// Send mail
mail('', $subject, $message, $headers, '-f ' . $from);
}

Sending multipart email from php, only download shows not the actual message

I'm struggling with sending my multipart email with plain text version as well as with HTML. Unfortunately when I receive it in Gmail it shows as downloadable message only as shown below:
The code is pasted below and although I went over like 100 questions here on SO I'm still stuck.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: donotreply#someaddress.com\r\n";
$headers .= "Subject: Test mail\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
// plain text version
$message .= $plainTextMessage;
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
// html version here
$message .= $htmlMessage;
$message .= "\r\n\r\n--" . $boundary . "--";
return #mail($to, $subject, $message, $headers);

Multiple recipients with PHP script?

So the issue is I want multiple recipients for my PHP form.
What happens is the site user enters there email and then another email for another peroson (for example there doctor).
So what I need is the the doctor to be emailed to.
This is what I am using to know success
$mail_to = $field_emaildoc .$field_email;
This doesent seem to work?
Any ideas would be great :)
Thanks
one option is to add a "Cc" to your header:
$sender_email = 'email#domain.com';
$sender_name = 'YOUR NAME';
$send_to = 'email#domain.com';
$send_to_copy = 'anotheremail#domain.com';
$message = 'THIS IS YOUR MESSAGE';
$subject = 'THIS IS YOUR SUBJECT';
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= "From: $sender_name<" . $sender_email . ">" . "\r\n";
$headers .= "X-Sender: $sender_name<" . $sender_email . ">" . "\n";
$headers .= "X-Mailer: PHP " . phpversion() . "\n";
$headers .= "X-Priority: 3" . "\n";
$headers .= "X-Sender-IP: " . $_SERVER['REMOTE_ADDR'] . "\n";
$headers .= "Return-Path: $sender_name<" . $sender_email . ">" . "\r\n";
$headers .= "Reply-To: $sender_name<" . $sender_email . ">" . "\r\n";
$headers .= "Cc: $send_to_copy" . "\r\n";
mail($send_to,$subject,$message,$headers);
The problem with this, is that the person receiving the email can see who was copied in. An alternative would be to use: "Bcc" instead of "Cc" or just use the mail() function twice and remove the "Cc" or "Bcc":
mail($send_to1,$subject,$message,$headers);
mail($send_to2,$subject,$message,$headers);
You should put comma between mail addresses . Look explanation of to parameter, here : http://php.net/manual/en/function.mail.php
You'll need a comma:
$mail_to = $field_emaildoc . ',' . $field_email;
Use the default mail function from PHP.
The recipients are devided by a Comma.
When you want CC and BCC you can set the header. Example from PHP.net:
$header .= 'To: Simone <simone#example.com>, Andreas <andreas#example.com>' . "\r\n";
$header .= 'From: Geburtstags-Erinnerungen <geburtstag#example.com>' . "\r\n";
$header .= 'Cc: geburtstagsarchiv#example.com' . "\r\n";
$header .= 'Bcc: geburtstagscheck#example.com' . "\r\n";
mail($empfaenger, $betreff, $nachricht, $header);

Sending HTML email in PHP

I am working on an HTML page where i need to send confirmation by HTML email using PHP.
I don't have much experience in PHP as i occasionally work on PHP.
I am able to send the HTML email using PHP and it comes up nice except the IMAGE part.
I have checked about 30 example and implement different ways of but non works.
When i check the source code of email it shows image part as
<img src="http://www.xyz.com/images/emailheader.jpg\"">
<img src="http://www.xyz.com/images/emailheader.jpg\";" alt="mage"">
Code for HTML
$subject = 'Confirmation';
$message = '<table ><tr><td><img src=\"http://www.xyz.com/images/emailheader.jpg\" /></td></tr><tr><td >'. "\r\n";
$message .= '<img src=\"http://www.xyz.com/images/emailheader.jpg\"; alt="Image" />';
$message .= 'Title <br/><br/>'. "\r\n";
$message .= 'Dear '. $_SESSION['FN'] . ' '.$_SESSION['LN'].'<br/><br/>'. "\r\n";
$message .= ' <br/><br/>'. "\r\n";
$message .= 'Name: '. $_SESSION['FN'] . ' '.$_SESSION['LN'].'<br/>'. "\r\n";
$message .= 'Email: '. $_SESSION['Email'].'<br/>'. "\r\n";
$message .= '<br/><br/>.'. "\r\n";
$message .= '<br/><br/>Best Regards,'. "\r\n";
$message .= '</td></tr></table>';
//Headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n";
$headers .= 'From: booking#xyz.com' . "\r\n";
$headers .= 'Reply-To: abc#xyz.com' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
ini_set ( "SMTP", "smtp.abc.com" );
I would appreciate if some can correct my code or at-least tell me what i am doing wrong
problem is in this line:
'<img src=\"http://www.alfarooqcentre.com/images/emailheader.jpg\"; alt="Image" />';
remove "\" and ";"
or check this tutorial, there is what you want.
http://phpform.net/html_mail.php

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