Rowno Posted April 30, 2008 Share Posted April 30, 2008 I'm trying to create a mail form for the Contact Us page of my website, but the emails aren't being sent. Here's the code I used for the mail function: <?php $finalmessage = ' <!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 { background: #000000; font-family: Arial; font-size: 13px; color: #999999; } A:LINK { color: #CCCCCC; text-decoration: none; } A:VISITED { color: #CCCCCC; text-decoration: none; } A:ACTIVE { color: #CCCCCC; text-decoration: none; } A:HOVER { color: #FFFFFF; text-decoration: underline; } </style> </head> <body> This email was sent by '.$name.' from the WEB SPIRITED Contact Us mail form and they sent this message:<br /> '.$message.' <p> Their reply email address is: <a href="mailto:'.$email.'">'.$email.'</a> </body> </html> '; $finalmessage = wordwrap($finalmessage, "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 .= 'X-Mailer: PHP 5.2.5' . "\r\n"; $headers .= 'Reply-To: ' . $email . "\r\n"; if (mail($toemail, $subject, $finalmessage, $headers)) { $success = "Your email has been sent."; } ?> Don't worry about the variables, because I've checked them and they're all being set correctly. The strange thing is that I have another mail script on my website that works fine so I know I can send mail, and if I put the message from that function into this one, it sends fine. If I add the message from the other script or filler text to the top of the <body> of this message it also sends fine so it's got something to do with this message. Also, my server sends/receives it's mail through the Google mail server if that has anything to do with the problem. Can anyone please help me? This is very frustrating. Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/ Share on other sites More sharing options...
theinfamousmielie Posted April 30, 2008 Share Posted April 30, 2008 Heya, $headers .= 'From: WEB SPIRITED <from email here>' . "\r\n"; Have you tried putting in a legitimate email address? mail() might be having issues with that... Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530136 Share on other sites More sharing options...
Rowno Posted April 30, 2008 Author Share Posted April 30, 2008 There is a real address in there in the actual script, I just took it out for the forum . Do you have any other ideas why it shouldn't work?, cause I'm completely lost ??? Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530138 Share on other sites More sharing options...
theinfamousmielie Posted April 30, 2008 Share Posted April 30, 2008 Hahaha, okay, fair enough. Re-read your post ... makes sense okay ... 1) at the top of your script, add: error_reporting(E_ALL) 2) Check if you get any errors, if so, paste them in 3) Secondly, add the following above your current mail() function ... run the script and paste the result in var_dump(mail($toemail, $subject, $finalmessage, $headers)); Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530139 Share on other sites More sharing options...
Rowno Posted April 30, 2008 Author Share Posted April 30, 2008 For that first error reporting function, it said all my POST and SESSION variables were Undefined index:, whatever that means, still got to do the second one. Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530144 Share on other sites More sharing options...
theinfamousmielie Posted April 30, 2008 Share Posted April 30, 2008 Lol, okay ... paste the exact messages in, even the undefined posts and sessions. Sometimes the strangest things can cause problems down the line Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530146 Share on other sites More sharing options...
Rowno Posted April 30, 2008 Author Share Posted April 30, 2008 Here's the results from the first error function: Notice: Undefined index: loggedin in /home/webspiri/public_html/webspirited/contactus.php on line 6 Notice: Undefined index: subject in /home/webspiri/public_html/webspirited/contactus.php on line 12 Notice: Undefined index: title in /home/webspiri/public_html/webspirited/contactus.php on line 13 Notice: Undefined index: lastname in /home/webspiri/public_html/webspirited/contactus.php on line 14 Notice: Undefined index: email in /home/webspiri/public_html/webspirited/contactus.php on line 15 Notice: Undefined index: message in /home/webspiri/public_html/webspirited/contactus.php on line 16 Notice: Undefined index: security_code in /home/webspiri/public_html/webspirited/contactus.php on line 17 Notice: Undefined index: submit in /home/webspiri/public_html/webspirited/contactus.php on line 20 Notice: Undefined index: loggedin in /home/webspiri/public_html/webspirited/contactus.php on line 202 Notice: Undefined index: loggedin in /home/webspiri/public_html/webspirited/contactus.php on line 243 Notice: Undefined index: loggedin in /home/webspiri/public_html/webspirited/contactus.php on line 292 Notice: Undefined index: level in /home/webspiri/public_html/webspirited/contactus.php on line 339 Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530151 Share on other sites More sharing options...
Rowno Posted April 30, 2008 Author Share Posted April 30, 2008 And here's the result from the second error function: bool(true) Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530154 Share on other sites More sharing options...
theinfamousmielie Posted April 30, 2008 Share Posted April 30, 2008 Hmmm ... well i just took your code and popped it in a script and tested it on my side ... and i get mail (even from <from email here> hahaha) however, i do see that you're using linux but you're using \r\n in your headers ... try using only \n (\r\n is windows based newline character) Also, check that $message doesn't have any unescaped ' (apostrophe's) in it ... or at least before you insert it use the addslashes() to see if it makes any difference I might be talking out my ass here, because apart from those two things, i don't see any problems that could be causing this! Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530164 Share on other sites More sharing options...
Rowno Posted April 30, 2008 Author Share Posted April 30, 2008 Unfortunately that didn't help and like I said in my starting post, if I add the message from the other working mail script or filler text to the top of the <body> of this message it sends the email fine. Since my server uses the Google mail server, do you think Google could be blocking the email from arriving? Here's the other, working, mail script: <?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 sent 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=\"http://www.webspirited.com/index.php?edit=activation&activationcode=$activationcode\" title=\"Verify email and activate account\">http://www.webspirited.com/index.php?edit=activation&activationcode=$activationcode</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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530183 Share on other sites More sharing options...
theinfamousmielie Posted April 30, 2008 Share Posted April 30, 2008 hmm ... it could be google that's having issues with it, but i'm not sure why they would. if you're developing in Windows ... i can recommend PostCast Server ... it's free, google it and download and install and set your php.ini to point to the name you specify and you have a mailserver on your local machine at least then you can know that your code is right without sending mail after mail. I use it, and it's saved me lots of heartache! I'm sorry i can't be of more help, i just don't get it. hehe. Quote Link to comment https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/#findComment-530184 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.