doctor_james Posted October 14, 2007 Share Posted October 14, 2007 hi , what's wrong with this code . it doesn't work ! <?php $address="AnEmailAddress"; $headers = "From: info@pgtt.ir\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $boundary = uniqid("HTMLDEMO"); $headers .= "Content-Type: multipart/alternative "."; boundary = $boundary\r\n\r\n"; $headers .= "This is a MIME encoded message.\r\n\r\n"; $headers .= "--$boundary\r\n" ."Content-Type: text/plain; charset=utf-8\r\n"."Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode("This is the plain text version!")); $headers .= "--$boundary\r\n" ."Content-Type: text/html; charset=ISO-8859-1\r\n"."Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode("This the <b>HTML</b> version!")); mail($address, "An HTML Message", "", $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/ Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 doesn't work how? error...? fails to send..? etc? try this.. <?php send_mail("test@domain.com", "Hello world", "Test Email", "Me@me.com", "My Name") function send_mail($to, $body, $subject, $fromaddress, $fromname, $attachments=false) { $eol="\r\n"; $mime_boundary=md5(time()); # Common Headers $headers .= "From: ".$fromname."<".$fromaddress.">".$eol; $headers .= "Reply-To: ".$fromname."<".$fromaddress.">".$eol; $headers .= "Return-Path: ".$fromname."<".$fromaddress.">".$eol; // these two to set reply address $headers .= "Message-ID: <".time()."-".$fromaddress.">".$eol; $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters # Boundry for marking the split & Multitype Headers $headers .= 'MIME-Version: 1.0'.$eol.$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol; # Open the first part of the mail $msg = "--".$mime_boundary.$eol; $htmlalt_mime_boundary = $mime_boundary."_htmlalt"; //we must define a different MIME boundary for this section # Setup for text OR html - $msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol.$eol; # Text Version $msg .= "--".$htmlalt_mime_boundary.$eol; $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol; $msg .= strip_tags(str_replace("<br>", "\n", substr($body, (strpos($body, "<body>")+6)))).$eol.$eol; # HTML Version $msg .= "--".$htmlalt_mime_boundary.$eol; $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol; $msg .= $body.$eol.$eol; //close the html/plain text alternate portion $msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol; if ($attachments !== false) { for($i=0; $i < count($attachments); $i++) { if (is_file($attachments[$i]["file"])) { # File for Attachment $file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1)); $handle=fopen($attachments[$i]["file"], 'rb'); $f_contents=fread($handle, filesize($attachments[$i]["file"])); $f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode(); $f_type=filetype($attachments[$i]["file"]); fclose($handle); # Attachment $msg .= "--".$mime_boundary.$eol; $msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol; // sometimes i have to send MS Word, use 'msword' instead of 'pdf' $msg .= "Content-Transfer-Encoding: base64".$eol; $msg .= "Content-Description: ".$file_name.$eol; $msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !! $msg .= $f_contents.$eol.$eol; } } } # Finished $msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection. # SEND THE EMAIL ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used ! $mail_sent = mail($to, $subject, $msg, $headers); ini_restore(sendmail_from); return $mail_sent; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369170 Share on other sites More sharing options...
doctor_james Posted October 14, 2007 Author Share Posted October 14, 2007 even mail(address,subject,body) doesn't work ! Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369277 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 "doesn't work" isn't usefull the reason it "doesn't work" is because its broken try my example and give more info please Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369294 Share on other sites More sharing options...
doctor_james Posted October 14, 2007 Author Share Posted October 14, 2007 Thanks for your replies . I tried your code but it fails to send . even that simple mail() function doesn't send anything . Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369304 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 is it your server, shared, etc ? has the mail been setup in PHP.INI, ie pop3_server=mail.yourdomain.com pop3_username=you@yourdomain.com pop3_password=mysecretpassword ; if your smtp server requires authentication, modify the following two lines ;auth_username= ;auth_password= Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369305 Share on other sites More sharing options...
doctor_james Posted October 15, 2007 Author Share Posted October 15, 2007 How can I find out it's set in php.ini . and yes it's shared . Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369844 Share on other sites More sharing options...
MadTechie Posted October 15, 2007 Share Posted October 15, 2007 you could use ini_set('sendmail_from', 'my@account'); Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369865 Share on other sites More sharing options...
doctor_james Posted October 15, 2007 Author Share Posted October 15, 2007 doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369909 Share on other sites More sharing options...
MadTechie Posted October 15, 2007 Share Posted October 15, 2007 use phpmailer.. may be more helpfull Quote Link to comment https://forums.phpfreaks.com/topic/73183-html-email/#findComment-369911 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.