I Need Help On Email Script - Webmasters - Nairaland
Nairaland Forum › Science/Technology › Webmasters › I Need Help On Email Script (847 Views)
| I Need Help On Email Script by widesmile(op): 10:55am On Sep 04, 2012 |
Pls I dont know if anyone can help me with writting an HTML supported code for email for gmail, the code works fine for yahoo mails but when I tried sending the same mail to gmail It comes out plain i.e the links can't be clicked and image could not display, here is a sample of the script <html> <head> <title>My Mail Sent!</title> </head> <body> <?php $mymessage = "<html><table><tr><td width=\"700\" height=\"400\" bgcolor=\"#00FF00\">Just to try this link!<a href=\"http://www.mytestdomain.com\" >Click here to view<a><br> <img src=\"http://www.mytestdomain.com/training/postcards/slider2.png\"> </td></tr></table></html>"; $to = "yourmail@yahoo.com,"; $from = "mymail@yahoo.com"; $subject = "Testing"; $messagebody = $mymessage; $boundary = '==MP_Bound_xyccr948x=='; $headers = array(); $headers[] = 'MIME-Version: 1.0'; $headers[] = 'Content-type: multipart/alternative; boundary="' . $boundary . '"'; $headers[] = 'From: ' . $from; $mail_message = 'This is a Multipart Message in MIME format' . "\n"; $mail_message .= '--' . $boundary . "\n"; $mail_message .= 'Content-type: text/html; charset="iso-8859-1"' . "\n"; $mail_message .= 'Content-Transfer-Encoding: 7bit' . "\n\n"; $mail_message .= $messagebody . "\n"; $mail_message .= '--' . $boundary . "\n"; $mail_message .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n"; $mail_message .= 'Content-Transfer-Encoding: 7bit' . "\n\n"; $mail_message .= strip_tags(messagebody) . "\n"; $mail_message .= '--' . $boundary . '--' . "\n"; $mailsent = mail($to, $subject, $mail_message, join("\r\n", $headers)); if ($mailsent) { echo "Congrats! The following message has been sent: <br><br>"; echo "<b>To:</b> $to<br>"; echo "<b>From:</b> $from<br>"; echo "<b>Subject:</b> $subject<br>"; echo "<b>Message:</b><br>"; echo $mail_message; } else { echo "There was an error..."; } ?> </body> </html> I won't mind if you help me with this or help me out with a new one Thanks |
| Re: I Need Help On Email Script by guru01(m): 1:34pm On Sep 04, 2012*. Modified: 10:51pm On Sep 04, 2012 |
For what i have experienced. google has a way of displaying emails which is quiet different from other email servers. Just try to be simple and don't do anything complex so that google won't suspect your email message. i Think the content-type should be tex/html instead |
| Re: I Need Help On Email Script by hostingnaija: 1:41pm On Sep 04, 2012 |
I am not an expert in the way Gmail treats HTML Emails, but consider using a boilerplate for creating valid messages, like http://htmlemailboilerplate.com/. Good luck and let us know if when you get it fixed! |
| Re: I Need Help On Email Script by DualCore1: 3:01pm On Sep 04, 2012 |
I have striped out a lot of unnecessary stuff from your code and have given the header a different content type declaration. Tested and works, here's it: <?php $mymessage = "<html><table><tr><td width=\"700\" height=\"400\" bgcolor=\"#00FF00\">Just to try this link!<a href=\"http://www.mytestdomain.com\" >Click here to view<a><br> <img src=\"http://www.mytestdomain.com/training/postcards/slider2.png\"> </td></tr></table></html>"; $to = "you@gmail.com"; $from = "me@yahoo.com"; $subject = "Testing"; $headers = "From: $from\n"."Reply-To: $from\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; if(mail($to, $subject, $mymessage, $headers)){ echo "Mail sent"; } else{ die('Mail died'); } ?> |
| Re: I Need Help On Email Script by widesmile(op): 4:21pm On Sep 04, 2012 |
@Dual core u r a life saver tanx soooooooooooooo much |
| Re: I Need Help On Email Script by widesmile(op): 4:27pm On Sep 04, 2012 |
I wld also like to say thank you to everyone that offered assitance |
| Re: I Need Help On Email Script by yawatide(f): 8:01pm On Sep 04, 2012 |
he he, dual core good o. I am just wondering when he will upgrade to quad core ![]() |
| Re: I Need Help On Email Script by Nobody: 4:12am On Sep 05, 2012 |
I wrote a script like this once, but i eventually went for phpmailer5, saves you the stress, can even use smtp. and the latest version can even embed images in the email - as inline attachments |
Get Your Form To Email Script With Auto-responder Facility. • Php Form To Email Script • 2 • 3 • 4
I Need A Full Time Web Development Job • Creating A Minisite • Hey Guys, So Why Do People Pay For Web Hosting When Webs.com Is Free ?