Rowno Posted April 28, 2008 Share Posted April 28, 2008 Can anyone tell me why this script isn't sending any emails? <?php $message = " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <title>$subject</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /> <style> body { font-family:Arial; } </style> </head> <body> This email was sent by $name from the WEB SPIRITED Contact Us mail form and they sent this message:<br /> $message <br /> Their reply email address is: $email </body> </html> "; $message = wordwrap($message, "70"); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type:text/html;charset=iso-8859-1' . "\r\n"; $headers .= 'From: WEB SPIRITED <from email here>' . "\r\n"; $headers .= 'Reply-To: '.$email . "\r\n"; if ($subject == "I would like a website made") {$toemail = "email 1";} else {$toemail = "email 2";} if (mail($toemail, $subject, $message, $headers)) { $success = "Your email has been sent."; } ?> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 28, 2008 Share Posted April 28, 2008 No. where are you running the script? is it on your own machine or a live server somewhere? Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted April 28, 2008 Share Posted April 28, 2008 Hello, had a similar problem with HTML based email not to long ago myself.. After pleanty of agravasion and trial and error and help from here even.. I got all to work.. <?php $to = $_POST['ref_trmail']; $subject = '[Poetry Asylum] - ' . $ptitle; $message = ' Your message here, including HTML markup.. '; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n"; $headers .= 'From: Poem Share <poetry@poetryasylum.com>' . "\r\n"; $headers .= 'To: ' . $_POST['ref_trname'] . ' <' . $_POST['ref_trmail'] . '>' . "\r\n"; $headers .= 'Reply-To: ' . $_POST['ref_yrname'] . ' <' . $_POST['ref_yrmail'] . '>' . "\r\n"; $headers .= '1\r\nX-MSMail-Priority: High' . "\r\n"; $headers .= 'X-Mailer: Poetry Asylum mailer v1.0' . "\r\n"; mail($to, $subject, $message, $headers); now heres where I got thrown off and looks similar to you one... your escapes of the double quotes in the message, take them out just leave the plain double quote like you would in any other html doc... two pay attention to my version vs yours.. notice the single quotes vs the double quotes, and where they are placed.. thrid you may wanna change it up a smidge as I have left headers and what not that pertain to mine as im just copy an pasting it out of one of my files for examples sake.. fourth when you have changed what you need and added your stuff in the part that says your message here you should have a fully functional HTML sending php mailer.. Enjoy Quote Link to comment Share on other sites More sharing options...
Rowno Posted April 28, 2008 Author Share Posted April 28, 2008 There is nothing wrong with the message, as I echoed out the variables to see if they were being set and the html message looked perfect and the my server does send mail because I have another mail script on my site that works perfectly but for some reason this script doesn't. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 28, 2008 Share Posted April 28, 2008 OK shot in the dark as I suspect this is actually part of a bigger script but I don't see $subject being set anywhere... In fact none of them are 'Set' anywhere in the script so perhaps you could post all the preceeding code also... Quote Link to comment Share on other sites More sharing options...
Rowno Posted April 28, 2008 Author Share Posted April 28, 2008 I echoed out all the variables that are inputed into the mail function and they're all being set. Quote Link to comment Share on other sites More sharing options...
Rowno Posted April 28, 2008 Author Share Posted April 28, 2008 Ok, here's my other mail script that works perfectly: <?php $subject = "WEB SPIRITED Email Verification and Account Activation"; $message = " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <title>WEB SPIRITED Email Verification and Account Activation</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /> <style> body { font-family:Arial; } </style> </head> <body> This email was send by WEB SPIRITED to verify that the email address you entered is correct and to activate your account.<br /> Please click on the link below to verify this email address and to activate your account. <p> <br /> <a href=\"link" title=\"Verify email and activate account\">link</a> <p> <br /> If this link isn't working, copy and paste the address into the address field of your internet browser. </body> </html> "; $message = wordwrap($message, "70"); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type:text/html;charset=iso-8859-1' . "\r\n"; $headers .= 'From: WEB SPIRITED <from email here>' . "\r\n"; mail($email, $subject, $message, $headers); ?> Can anyone see any reason why the script above shouldn't work compared to this one? Because they're both run on the same server and same site. Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 29, 2008 Share Posted April 29, 2008 try this fill in the correct info <?php $message = " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <title>$subject</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /> <style> body { font-family:Arial; } </style> </head> <body> This email was sent by $name from the WEB SPIRITED Contact Us mail form and they sent this message:<br /> $message <br /> Their reply email address is: $email </body> </html> "; $mess = wordwrap($message, "70"); $subject == "I would like a website made"; $name=" name off user"; $to="to the user email address"; $email=" from address email" $to = $to; $subject = $subject; $message = $mess; $headers = "From: $email\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; if ($subject == "I would like a website made"){ $toemail = "email 1"; }else{ $toemail = "email 2"; } if (mail($to, $subject, $message, $headers)){ $success = "Your email has been sent."; } ?> Quote Link to comment Share on other sites More sharing options...
Rowno Posted April 29, 2008 Author Share Posted April 29, 2008 Ok, after a load of testing, it seems that the email is only being sent/received if there is at least certain amount of content in it, does anyone know why this might be? ??? Quote Link to comment Share on other sites More sharing options...
Rowno Posted April 29, 2008 Author Share Posted April 29, 2008 This is so frustrating, if I use the message from the working mail script it works but if I use the message from the not working mail script it doesn't work. So this means it's something in the message that's causing the problem, but what... ??? Quote Link to comment 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.