1

I'm trying to create a booking system that when a user books and event it sends an e-mail to the required people, most of it works now but I'm having trouble with the e-mail system.

The e-mail only sends to the $to and not to the CC:. Also it is sent by the hosting server and does not show the FROM:. I've read a few pages which says the order of the headings are important, but I can't seem to find the right order.

Here is the code

 $to = 'crnflying@gmail.com';

$subject = $this->rank . ' ' . $this->first_name . ' ' . $this->last_name;

$message = '
<html>
<body>
<img style="float: right;" src="http://www.emuas.co.uk/templates/emuas-public/images/emuas-title.png" alt="emuas-logo">
<h2>EMUAS Flying Booking for ' . $this->rank . ' ' . $this->first_name . ' ' . $this->last_name . '</h2>
<table style="border-color: #666;" cellpadding="10">
<tr>
<td><strong>Start Date:</strong> </td>
<td>' . $this->flying_start_date . '</td>
</tr>
<tr>
<td><strong>End Date:</strong> </td>
<td>' . $this->flying_end_date . '</td>
</tr>
<tr>
<td><strong>Comments:</strong> </td>
<td>' . $this->flying_comments . '</td>
</tr>
</table>
</body>
</html>'

$headers = 'MIME-Version: 1.0' . '\r\n';
$headers .= 'Content-type:text/html;charset=iso-8859-1' . '\r\n';
$headers .= 'From: <' . $this->email . '>' . '\r\n';
$headers .= 'Reply-To: ' . $this->email . '\r\n';
$headers .= 'CC: ' . $this->email . '\r\n';

if (mail($to, $subject, $message, $headers)) {
echo 'Your message has been sent.';                                 }
else {
echo 'There was a problem sending the email.';
}

Any help would be much appreciated. Byron

  • 3
    Order of headers isn't important unless you repeat them. What your problem here is is that you have single-quoted `\r\n` causing them not to be correctly interpreted as the escape characters for carriage return and line feed. Double-quote those instead. ([PHP strings manual](http://us3.php.net/manual/en/language.types.string.php)) – Michael Berkowski Nov 12 '13 at 16:39
  • However, since this is causing you trouble I _highly_ recommend using a 3rd party mailer class to handle all the idiosyncratic heavy lifting for you. http://phpmailer.worxware.com/ Properly sending MIME mail in PHP is really hard, and even if you think you've done it right, it may still go to spam. Let other people do the work for you :) – Michael Berkowski Nov 12 '13 at 16:39
  • Ahh ok I'll give the third party mailer a go. thank you for the help – Byron Fitzgerald Nov 12 '13 at 16:54
  • Please.. use a proper library to send MIME emails. Preferably ones that contain a text version, too. – ThiefMaster Nov 12 '13 at 17:10

1 Answers1

0

to expand on what ThiefMaster or Michael were saying(in the comments), you should try Swiftmailer or other libraries dedicated to email generation. Its MUCH more reliable than "mail();" especially if your wanting to write / use / send information thats important for your customers.

Check out http://swiftmailer.org/

Not a difficult change at all. Essentially download the library, include it in your app, remove your "mail();" code and insert the one that Swiftmailer uses(or the one you need, they have a few options) and thats it.

You will need your email accounts login information / port / etc. to send reliable information. Your app will be as reliable as sending an email from your own webmail app.

Good luck

somdow
  • 6,268
  • 10
  • 40
  • 58