pixeltrace Posted April 10, 2007 Share Posted April 10, 2007 guys, i need help on this script i got this from another site. it is a sendmail script that can send HTML email when i test it, the header, subject, etc is ok except for the body or the message because its not appearing on my test mails. hope you could help me figure out the problem why its not showing the message or body part of the email below is the codes <?php //define the receiver of the email $to = 'youraddress@example.com'; //define the subject of the email $subject = 'Test HTML email'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> --PHP-alt-<?php echo $random_hash; ?>-- <? //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> thanks! Quote Link to comment https://forums.phpfreaks.com/topic/46449-need-help-on-this-sendmail-script/ Share on other sites More sharing options...
pixeltrace Posted April 10, 2007 Author Share Posted April 10, 2007 any help for this one please Quote Link to comment https://forums.phpfreaks.com/topic/46449-need-help-on-this-sendmail-script/#findComment-225993 Share on other sites More sharing options...
pixeltrace Posted April 11, 2007 Author Share Posted April 11, 2007 help please thanks! Quote Link to comment https://forums.phpfreaks.com/topic/46449-need-help-on-this-sendmail-script/#findComment-226526 Share on other sites More sharing options...
bobleny Posted April 11, 2007 Share Posted April 11, 2007 Try this: <?php $to = 'youraddress@example.com'; $subject = 'Test HTML email'; $message = 'Hello, this is a test.'; $mail = mail($to, $subject, $message); echo $mail; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46449-need-help-on-this-sendmail-script/#findComment-226531 Share on other sites More sharing options...
rcorlew Posted April 11, 2007 Share Posted April 11, 2007 Need more of the script, are you posting to it to create the message? Your message seems not to be defined. That is why I ask. Try this and let me know. <?php //define the receiver of the email $to = 'youraddress@example.com'; //define the subject of the email $subject = 'Test HTML email'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //define the body of the message. //ob_start(); //Turn on output buffering $message = "<h1>My message</h1><p align='center'>This is an html message</p>"; //copy current buffer contents into $message variable and delete current output buffer //$message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46449-need-help-on-this-sendmail-script/#findComment-226536 Share on other sites More sharing options...
pixeltrace Posted April 11, 2007 Author Share Posted April 11, 2007 Hi, the date, subject and header is correct. but the message is being sent as a file not HTML the file is "noname" with no extension file. hope you could help me fix this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/46449-need-help-on-this-sendmail-script/#findComment-226571 Share on other sites More sharing options...
rpadilla Posted April 11, 2007 Share Posted April 11, 2007 Hi, sometimes if you are using webmail to access to email or some other email clients, i't will show as attachment, some show them as html. Try using other email client, maybe it would show as html. Quote Link to comment https://forums.phpfreaks.com/topic/46449-need-help-on-this-sendmail-script/#findComment-226640 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.