indigoallan Posted January 15, 2008 Share Posted January 15, 2008 Hi, I am new to PHP though I have managed to get it installed and running on a Windows XP machine. I am having difficulties in sending data from forms to an eMail recipient. I found a script which runs but it always reports that the mail has failed to send. Has anyone had any similar problems and how could I overcome this problem? Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/ Share on other sites More sharing options...
The Little Guy Posted January 15, 2008 Share Posted January 15, 2008 have you installed a mail server? Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440092 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 U have hMailServer running on the machine and port 25 is open, but I am unsure whether I need another mail server for scripts to make us of? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440095 Share on other sites More sharing options...
revraz Posted January 15, 2008 Share Posted January 15, 2008 Would be helpful to see The error The code Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440098 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <title>Contact Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> <form name="form1" method="post" action="<?php echo $me;?>"> <table border="0" cellspacing="0" cellpadding="2"> <tr> <td>Name:</td> <td><input type="text" name="Name"></td> </tr> <tr> <td>Subject</td> <td><input type="text" name="Subject"></td> </tr> <tr> <td valign="top">Message:</td> <td><textarea name="MsgBody"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php } else { error_reporting(0); $recipient = me@myemail.co.uk'; $subject = stripslashes($_POST['Subject']); $from = stripslashes($_POST['Name']); $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']); if (mail($recipient, $subject, $msg)) echo nl2br("<b>Message Sent:</b> To: $recipient Subject: $subject Message: $msg"); else echo "Message failed to send"; } ?> </body> </html> is the code. The error screen just says "Message failed to send" It is running at http://213.120.121.64/allan.php Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440099 Share on other sites More sharing options...
marcus Posted January 15, 2008 Share Posted January 15, 2008 Put quotes around your recipient. Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440101 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 sorry that was an editing error when I removed the email i was sending it to....they are present in the script Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440103 Share on other sites More sharing options...
revraz Posted January 15, 2008 Share Posted January 15, 2008 Missing { } for this IF statement if (mail($recipient, $subject, $msg)) *nevermind, its one big statement, but I noticed you don't include a FROM: header Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440104 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 still doesn't seem to work ??? Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440112 Share on other sites More sharing options...
revraz Posted January 15, 2008 Share Posted January 15, 2008 Lets see what you did Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440116 Share on other sites More sharing options...
revraz Posted January 15, 2008 Share Posted January 15, 2008 Also, did you setup the SMTP information in the php.ini file? Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440117 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 php.ini reads [mail function] ; For Win32 only. SMTP = localhost smtp_port = 25 for the mail server...... the script now looks like this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <title>Contact Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> <form name="form1" method="post" action="<?php echo $me;?>"> <table border="0" cellspacing="0" cellpadding="2"> <tr> <td>Name:</td> <td><input type="text" name="Name"></td> </tr> <tr> <td>Subject</td> <td><input type="text" name="Subject"></td> </tr> <tr> <td valign="top">Message:</td> <td><textarea name="MsgBody"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php } else { error_reporting(0); $recipient = me@myemail.co.uk'; $subject = stripslashes($_POST['Subject']); $from = stripslashes($_POST['Name']); $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']); if (mail($recipient, $subject, $msg)) echo nl2br("Message Sent: To: $recipient Subject: $subject Message: $msg"); else echo "Message failed to send"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440119 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 oops sorry am working with a remote PC to add to problems - never downloaded remote PC clipboard! Here it is <head> <title>Contact Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> <form name="form1" method="post" action="<?php echo $me;?>"> <table border="0" cellspacing="0" cellpadding="2"> <tr> <td>Name:</td> <td><input type="text" name="Name"></td> </tr> <tr> <td>Subject</td> <td><input type="text" name="Subject"></td> </tr> <tr> <td valign="top">Message:</td> <td><textarea name="MsgBody"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php } else { error_reporting(0); $recipient = 'me@myemail.co.uk'; $subject = stripslashes($_POST['Subject']); $from = stripslashes($_POST['Name']); $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']); {if (mail($recipient, $subject, $msg)) echo nl2br("Message Sent: To: $recipient Subject: $subject Message: $msg"); else echo "Message failed to send";} } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440120 Share on other sites More sharing options...
darkfreaks Posted January 15, 2008 Share Posted January 15, 2008 Try <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <title>Contact Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> <form name="form1" method="post" action="<?php echo $me;?>"> <table border="0" cellspacing="0" cellpadding="2"> <tr> <td>Name:</td> <td><input type="text" name="Name"></td> </tr> <tr> <td>Subject</td> <td><input type="text" name="Subject"></td> </tr> <tr> <td valign="top">Message:</td> <td><textarea name="MsgBody"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php } else { error_reporting(0); $recipient = 'me@myemail.co.uk'; $subject = stripslashes($_POST['Subject']); $from = stripslashes($_POST['Name']); $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']); if (mail($recipient, $subject, $msg)) echo nl2br("Message Sent: To: $recipient Subject: $subject Message: $msg"); }else{ echo "Message failed to send"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440124 Share on other sites More sharing options...
revraz Posted January 15, 2008 Share Posted January 15, 2008 For troubleshooting, make it easy Create a new file and just do <?php mail("youremail@email.com", "Subject", "Body", "FROM: noone@email.com"); ?> Replace youremail@email.com with your real email. If this doesnt work, its your mail server setup. Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440128 Share on other sites More sharing options...
darkfreaks Posted January 15, 2008 Share Posted January 15, 2008 were missing brackets <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <title>Contact Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> <form name="form1" method="post" action="<?php echo $me;?>"> <table border="0" cellspacing="0" cellpadding="2"> <tr> <td>Name:</td> <td><input type="text" name="Name"></td> </tr> <tr> <td>Subject</td> <td><input type="text" name="Subject"></td> </tr> <tr> <td valign="top">Message:</td> <td><textarea name="MsgBody"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php } else { error_reporting(0); $recipient = 'me@myemail.co.uk'; $subject = stripslashes($_POST['Subject']); $from = stripslashes($_POST['Name']); $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']); if (mail($recipient, $subject, $msg)){ echo nl2br("Message Sent: To: $recipient Subject: $subject Message: $msg");} }else{ echo "Message failed to send"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440131 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 Warning: mail() [function.mail]: SMTP server response: 550 Delivery is not allowed to this address. in C:\server\www\ticketyboos\public_html\allan.php on line 4 I reckon it is more server side problem that PHP coding? Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440138 Share on other sites More sharing options...
darkfreaks Posted January 15, 2008 Share Posted January 15, 2008 the mail function is turned off in your php.ini file it is disabled Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440139 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 I thought it was on!!! What extension should I enable then? http://213.120.121.64/phpinfo.php Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440141 Share on other sites More sharing options...
darkfreaks Posted January 15, 2008 Share Posted January 15, 2008 http://www.hmailserver.com/forum/viewtopic.php?p=28532&sid=e0af5c9a0061596160385126b86a43a5 tht should help you Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440145 Share on other sites More sharing options...
indigoallan Posted January 15, 2008 Author Share Posted January 15, 2008 Thank you so very much guys! Got it sorted finally! It was starting to stress me out! Now all I gotta get hold of is a customer database/membership php and something to control access into a staff only area and I'll be sorted THANKS Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440315 Share on other sites More sharing options...
revraz Posted January 15, 2008 Share Posted January 15, 2008 See this post for that http://www.phpfreaks.com/forums/index.php/topic,177361.0.html Quote Link to comment https://forums.phpfreaks.com/topic/86176-solved-form-processing-in-php-sendmail-function/#findComment-440327 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.