Multiple recipients with PHP script? - php

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);

Related

HTML Email occasionally sending source code

At my company, we have had several clients claim that their order confirmation emails are coming through just as the HTML source, not formatted at all. However the majority of our clients are receiving their emails through fine.
I think I may have found a link which explains why only some clients receive the unformatted email, however I'm not sure of the cause. It seems that users with a custom domain name for their email address are experiencing the problems and regular email domains such as #gmail.com or #icloud.com are working fine.
The problem is not related to the client used to view the email as I have been able to replicate the problem with my private domain name and the source code is displayed in all clients.
Any idea what would be the cause of this?
Here are my headers:
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "Return-Path: ".$from."\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
Try following headers for HTML Email...
$from = $from . ' <' . $from . '>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' . $from . "\r\n";
$headers .= 'Return-Path: ' . $from . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
$headers .= 'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'] . "\r\n";

Using a sender's name and email address in the header of a PHP email form

I can't get the syntax quite right with PHP. How do I change it to display the sender's full name as well as their email address in the 'From:' part this PHP email script?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['message'];
I tried
$headers .= "From: " . $_REQUEST['email'] '<'$_REQUEST['name']'>'. "\r\n";
But I've screwed up the code somewhere.
Thanks guys!
Mail headers are Person Name <email#example.com> so your header needs to be:
$headers .= "From: $_REQUEST[email] <$_REQUEST[name]>\r\n";

Plain text version of email is not working

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 :(

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