Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,156,168 members, 7,829,176 topics. Date: Wednesday, 15 May 2024 at 09:01 PM

I Need Help On Email Script - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / I Need Help On Email Script (771 Views)

Get Your Form To Email Script With Auto-responder Facility. / Php Form To Email Script (2) (3) (4)

(1) (Reply) (Go Down)

I Need Help On Email Script by widesmile(f): 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
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');
}
?>

1 Like

Re: I Need Help On Email Script by widesmile(f): 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(f): 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 cool tongue cool
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

(1) (Reply)

I Need GSM Short Code / Get A Free 30-day Trial On SEO Campaigns for your blog/website...!!! / How To Make The Mobile Version Of A Website.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 16
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.