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 = '[email protected]'; $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

4
  • 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) Commented Nov 12, 2013 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. 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 :) Commented Nov 12, 2013 at 16:39
  • Ahh ok I'll give the third party mailer a go. thank you for the help Commented Nov 12, 2013 at 16:54
  • Please.. use a proper library to send MIME emails. Preferably ones that contain a text version, too. Commented Nov 12, 2013 at 17:10

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.