mindapolis Posted December 19, 2011 Share Posted December 19, 2011 Can someone help me understand why an email isn't being sent after clicking submit? <?php error_reporting(E_ALL); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php extract ($_POST); if(!isset($submit)) { ?> <form action=" " method="post" name="test"> Name: <input name="name " type="text" id="name " size="8" /><br /> phone <input name="phone" type="text" size="13" /><br /> email <input name="email" type="text" size="9" maxlength="30" /><br /> <input name="submit" type="submit" value="submit" /> </form> <?php $Recipient = "$email"; $MsgSubject = "message subject"; $MsgHeader = "From Auntie Vic's Treatery <[email protected]>\r\n"; $MsgBody = "message body."; mail($Recipient, $MsgSubject, $MsgBody, $MsgHeader); } else { echo " thank you for your order. It is being processed. Thank you for your business."; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/ Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 Are you getting any errors? Also is it a local host or are you using a service? Because I had this problem today, and it was because godaddy does not send emails the the 'from' in the mail() function if it is from hotmail.com, yahoo.com, gmail.com, etc. Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299110 Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 sorry for double post Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299111 Share on other sites More sharing options...
btellez Posted December 19, 2011 Share Posted December 19, 2011 You can not send mail using the mail function after something has been sent to the browser... You need to call mail before you do any output... <?php /* process */ mail(/*appropriate parameters here*/); ?> <html> ......ect... See the PHP.net Documentation Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299112 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 Actually, yes this is through godaddy. Are there any solutions? Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299113 Share on other sites More sharing options...
Pikachu2000 Posted December 19, 2011 Share Posted December 19, 2011 Look at your logic. The mail function is only called if the form hasn't been submitted. That obviously isn't going to work that way. Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299114 Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 Actually, yes this is through godaddy. Are there any solutions? I just took out the 'from' function completely, now it just says that it is being sent by my godaddy email address Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299115 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 take off $MsgHeader = "From Auntie Vic's Treatery <[email protected]>\r\n"; ? Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299117 Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 take off $MsgHeader = "From Auntie Vic's Treatery <[email protected]>\r\n"; ? Just have: mail($Recipient, $MsgSubject, $MsgBody) And if you need their email address, just put it inside the email Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299119 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 That didn't work either. If I change if(!isset($submit)) to if(isset($submit)) then the thank you page doesn't come up <?php $Recipient = "$email"; $MsgSubject = "message subject"; $MsgBody = "message body."; mail($Recipient, $MsgSubject, $MsgBody); error_reporting(E_ALL); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php extract ($_POST); if(!isset($submit)) { ?> <form action=" " method="post" name="test"> Name: <input name="name " type="text" id="name " size="8" /><br /> email <input name="email" type="text" size="9" maxlength="30" /><br /> <input name="submit" type="submit" value="submit" /> </form> <?php } else { echo " thank you for your order. It is being processed. Thank you for your business."; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299133 Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 I have not tested it, but does this work? <?php error_reporting(E_ALL); if(isset($submit)) { extract ($_POST); $Recipient = "$email"; $MsgSubject = "message subject"; $MsgBody = "message body."; mail($Recipient, $MsgSubject, $MsgBody); echo " thank you for your order. It is being processed. Thank you for your business."; } else { echo " Error sending email"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action=" <?php echo $_SERVER['PHP_SELF']?>" method="post" name="test"> Name: <input name="name " type="text" id="name " size="8" /><br /> email <input name="email" type="text" size="9" maxlength="30" /><br /> <input name="submit" type="submit" value="submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299136 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 no Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299143 Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 Sorry, I got it wrong here is the code: <?php error_reporting(E_ALL); if(isset($_POST['submit'])) { $Recipient = $email; $MsgSubject = "message subject"; $MsgBody = "message body."; mail($Recipient, $MsgSubject, $MsgBody); echo " thank you for your order. It is being processed. Thank you for your business."; } else { echo " Error sending email"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action=" <?php echo $_SERVER['PHP_SELF']?>" method="post" name="test"> Name: <input name="name " type="text" id="name " size="8" /><br /> email <input name="email" type="text" size="9" maxlength="30" /><br /> <input name="submit" type="submit" value="submit" /> </form> </body> </html> BTW, I could see where you specified the variable $email? Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299144 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 if you do it that way $email isn't defined yet Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299149 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Change to $Recipient = $_POST['email']; Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299151 Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 if you do it that way $email isn't defined yet $recipient is the email address the email is being sent to. So it will be your email address. Which should be preferably constant Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299152 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 With the following code I get "thank you for your order. It is being processed. Thank you for your business." not the form <?php $Recipient = $_POST['$email']; $MsgSubject = "message subject"; $MsgBody = "message body."; mail($Recipient, $MsgSubject, $MsgBody); error_reporting(E_ALL); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php extract ($_POST); if(!isset($submit)) { ?> <form action=" " method="post" name="test"> Name: <input name="name " type="text" id="name " size="8" /><br /> ' email <input name="email" type="text" size="9" maxlength="30" /><br /> <input name="submit" type="submit" value="submit" /> </form> <?php } else { echo " thank you for your order. It is being processed. Thank you for your business."; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299157 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Maybe you should explain what you want the script to do, and then we can help you. Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299159 Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 I have just tested the code I posted before, and it worked. all you have to do is set $recipient as YOUR email address you want the email to go to Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299161 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 i need it to send an email to the person submitting the form Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299162 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 but the recipient may not be me. It's whoever fills out the fprm Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299166 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Okay, so in what way does melloorr's code fail to do that? Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299168 Share on other sites More sharing options...
melloorr Posted December 19, 2011 Share Posted December 19, 2011 but the recipient may not be me. It's whoever fills out the fprm Then just put: $recipient = $_POST['email']; Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299172 Share on other sites More sharing options...
mindapolis Posted December 19, 2011 Author Share Posted December 19, 2011 i did and it didn't send the email. <?php $Recipient = $_POST['$email']; $MsgSubject = "message subject"; $MsgBody = "message body."; mail($Recipient, $MsgSubject, $MsgBody); error_reporting(E_ALL); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php extract ($_POST); if(!isset($submit)) { ?> <form action=" " method="post" name="test"> Name: <input name="name " type="text" id="name " size="8" /><br /> ' email <input name="email" type="text" size="9" maxlength="30" /><br /> <input name="submit" type="submit" value="submit" /> </form> <?php } else { echo " thank you for your order. It is being processed. Thank you for your business."; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299179 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 You should carefully look at melloor's code and then back at your own and figure out where your problem is coming from. Quote Link to comment https://forums.phpfreaks.com/topic/253452-email-not-sending/#findComment-1299181 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.