kingtomato117 Posted July 4, 2008 Share Posted July 4, 2008 Ok, I'm new to PHP Scripting but not new to programming in general. But I need some help. I have a contact form where the user enters their email address, and name and subject and comments. Now its supposed to send me an email and an email to their inbox. Well it sends one to them but not me, but after they click submit they get a page saying their message has been sent. and it sends one to them but not to me. My mailErrors.log says email couldnt be sent address is outside your domain. I'll post the code below. i dont understand it why it would send to them and error log say outsaide of domain. The admin email i have it sent to is [email protected] and its defined in the php script. What bugs me is I have a helpdesk system on my site and when people create support tickets it sends to both me and them. Any help is appreciated. <?php /* PHP Form Mailer - phpFormMailer v2.2, last updated 23rd Jan 2008 - check back often for updates! (easy to use and more secure than many cgi form mailers) FREE from: www.TheDemoSite.co.uk Should work fine on most Unix/Linux platforms for a Windows version see: asp.thedemosite.co.uk */ // ------- three variables you MUST change below ------------------------------------------------------- $replyemail="[email protected]";//change to your email address $valid_ref1="http://virassisting.com/contact.html";// chamge "Your--domain" to your domain $valid_ref2="http://www.virassisting.com/contact.html";// chamge "Your--domain" to your domain // -------- No changes required below here ------------------------------------------------------------- // email variable not set - load $valid_ref1 page if (!isset($_POST['email'])) { echo "<script language=\"JavaScript\"><!--\n "; echo "top.location.href = \"$valid_ref1\"; \n// --></script>"; exit; } $ref_page=$_SERVER["HTTP_REFERER"]; $valid_referrer=0; if($ref_page==$valid_ref1) $valid_referrer=1; elseif($ref_page==$valid_ref2) $valid_referrer=1; if(!$valid_referrer) { echo "<script language=\"JavaScript\"><!--\n alert(\"ERROR - not sent.\\n\\nCheck your 'valid_ref1' and 'valid_ref2' are correct within contact_process.php.\");\n"; echo "top.location.href = \"contact.html\"; \n// --></script>"; exit; } //check user input for possible header injection attempts! function is_forbidden($str,$check_all_patterns = true) { $patterns[0] = 'content-type:'; $patterns[1] = 'mime-version'; $patterns[2] = 'multipart/mixed'; $patterns[3] = 'Content-Transfer-Encoding'; $patterns[4] = 'to:'; $patterns[5] = 'cc:'; $patterns[6] = 'bcc:'; $forbidden = 0; for ($i=0; $i<count($patterns); $i++) { $forbidden = eregi($patterns[$i], strtolower($str)); if ($forbidden) break; } //check for line breaks if checking all patterns if ($check_all_patterns AND !$forbidden) $forbidden = preg_match("/(%0a|%0d|\\n+|\\r+)/i", $str); if ($forbidden) { echo "<font color=red><center><h3>STOP! Message not sent.</font></h3><br><b> The text you entered is forbidden, it includes one or more of the following: <br><textarea rows=9 cols=25>"; foreach ($patterns as $key => $value) echo $value."\n"; echo "\\n\n\\r</textarea><br>Click back on your browser, remove the above characters and try again. </b><br><br><br><br>Thankfully protected by phpFormMailer freely available from: <a href=\"http://thedemosite.co.uk/phpformmailer/\">http://thedemosite.co.uk/phpformmailer/</a>"; exit(); } else return $str; } $name = is_forbidden($_POST["name"]); $email = is_forbidden($_POST["email"]); $thesubject = is_forbidden($_POST["thesubject"]); $themessage = is_forbidden($_POST["themessage"], false); $success_sent_msg='<p align="center"><strong> </strong></p> <p align="center"><strong>Your message has been successfully sent to us<br> </strong> and we will reply as soon as possible.</p> <p align="center">A copy of your query has been sent to you.</p> <p align="center">Thank you for contacting us.</p>'; $replymessage = "Hi $name Thank you for your email. We will endeavour to reply to you shortly. Please DO NOT reply to this email. Below is a copy of the message you submitted: -------------------------------------------------- Subject: $thesubject Query: $themessage -------------------------------------------------- Thank you"; $themessage = "name: $name \nQuery: $themessage"; mail("$replyemail", "$thesubject", "$themessage", "From: $email\nReply-To: $email"); mail("$email", "Receipt: $thesubject", "$replymessage", "From: $replyemail\nReply-To: $replyemail"); echo $success_sent_msg; /* PHP Form Mailer - phpFormMailer (easy to use and more secure than many cgi form mailers) FREE from: www.TheDemoSite.co.uk */ ?> Here is the html page code <html> <head> <title>PHP Form Mailer - phpFormMailer (easy to use and more secure than many cgi form mailers)</title> <style> BODY{color:#000000; font-size: 8pt; font-family: Verdana} .button {background-color: rgb(128,128,128); color:#ffffff; font-size: 8pt;} .inputc {font-size: 8pt;} .style3 {font-size: xx-small} </style> </head> <body> <form name="phpformmailer" action="contact_process.php" align="center" method="post"> <div align="center"><center><table bgcolor="#F2F2F2" width="742" cellspacing="6"> <tr> <td width="162"><strong>Contact Us</strong></td> <td width="556"><span class="style3">Protected by: <a href="http://thedemosite.co.uk/phpformmailer/">phpFormMailer</a> the freely available PHP form mailer</span></td> </tr> <tr> <td align="right" width="162"><small>Your name:</small></td> <td width="556"><font face="Arial"><input class="inputc" size="50" name="name"> </font></td> </tr> <tr> <td align="right" width="162"><font color="#000080" size="1">*</font><small> Your email address:</small></td> <td align="left" width="556"><font face="Arial"><input class="inputc" size="50" name="email"> </font></td> </tr> <tr align="middle"> <td align="right" width="162"><font color="#000080" size="1">*</font><small> Confirm email address:</small></td> <td width="556" align="left"><font face="Arial"><input class="inputc" size="50" name="email2"> </font></td> </tr> <tr> <td align="right" width="162"><font color="#000080" size="1">*</font><small> Subject:</small></td> <td width="556"><font face="Arial"><input class="inputc" size="60" name="thesubject"> </font></td> </tr> <tr> <td align="right" width="162"> <p><font color="#000080" size="1">*</font><small> Your request or query:</small></td> <td width="556"><textarea style="FONT-SIZE: 10pt" name="themessage" rows="7" cols="60"></textarea></td> </tr> <tr> <td width="162"></td> <td width="556"><p> <input type="button" class="button" value="Send" name="B1" ONCLICK="javascript:validateForm()"> <small> <small>You must fill in the fields marked with a *</p> </td> </tr> </table> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><span class="style3">Protected by: <a href="http://thedemosite.co.uk/phpformmailer/">phpFormMailer</a> the freely available PHP form mailer</span></p> </center></div> </form> <script language="JavaScript"><!-- function validateForm() { var okSoFar=true with (document.phpformmailer) { var foundAt = email.value.indexOf("@",0) if (foundAt < 1 && okSoFar) { okSoFar = false alert ("Please enter a valid email address.") email.focus() } var e1 = email.value var e2 = email2.value if (!(e1==e2) && okSoFar) { okSoFar = false alert ("Email addresses you entered do not match. Please re-enter.") email.focus() } if (thesubject.value=="" && okSoFar) { okSoFar=false alert("Please enter the subject.") thesubject.focus() } if (themessage.value=="" && okSoFar) { okSoFar=false alert("Please enter the details for your enquiry.") themessage.focus() } if (okSoFar==true) submit(); } } // --></script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/113224-php-script-help/ Share on other sites More sharing options...
compguru910 Posted July 4, 2008 Share Posted July 4, 2008 From what your saying, and what that script is saying, I think you have it way over complicated. Try something like this //Checks to see if the submit button on the page was hit if (isset($_POST['submit'])) { $commenters_email = $_POST['email']; $comment = $_POST['comment']; $message_body = "Make up your message to the sender here, remember to use \n for new lines"; mail ('[email protected]','subject line',$comment); mail ($commenters_email,'Reply',$message_body); } Hope that this helps! Quote Link to comment https://forums.phpfreaks.com/topic/113224-php-script-help/#findComment-581679 Share on other sites More sharing options...
PFMaBiSmAd Posted July 4, 2008 Share Posted July 4, 2008 The From: email address must be a valid email address at the sending mail server (even if you are sending it just within your mail server, as in - From: yourself To: yourself.) Change the following - "From: $email\nReply-To: $email"); to "From: $replyemail\nReply-To: $email"); Quote Link to comment https://forums.phpfreaks.com/topic/113224-php-script-help/#findComment-581680 Share on other sites More sharing options...
kingtomato117 Posted July 4, 2008 Author Share Posted July 4, 2008 Ok what compguru gave me worked, but i modified it abit and got this: <title>Thank you for your feedback</title><?php //Checks to see if the submit button on the page was hit if (isset($_POST['submit'])) { $name = $_POST['name']; $commenters_email = $_POST['email']; $comment = $_POST['comment']; $subject = $_POST['subject']; $msgrecieved = '<p align="center"><strong> </strong></p> <p align="center"><strong>Your message has been successfully sent to us<br> </strong> and we will reply as soon as possible.</p> <p align="center">A copy of your query has been sent to you.</p> <p align="center">Thank you for contacting us.</p>'; $message_body = "Hi $name Thank you for your email. We will reply shortly. If you do not hear from us in 24 hours, please contact us again. Please DO NOT reply to this email. Below is a copy of the message you submitted: -------------------------------------------------- Subject: $subject Query: $comment -------------------------------------------------- Thank you"; mail ('[email protected]','Feedback from VirAssisting.com',$name,$commenters_email,$comment); mail ($commenters_email,'Thank you for your feedback',$message_body); } echo $msgrecieved; ?> but this line mail ('[email protected]','Feedback from VirAssisting.com',$name,$commenters_email,$comment); it sends two emails like it should one to me and one to user but it'll onlysend $name and $commenters_email but not comment. It would send comment fine before i added those any ideas? EDIT: It also wont send subject in $message_body Quote Link to comment https://forums.phpfreaks.com/topic/113224-php-script-help/#findComment-581735 Share on other sites More sharing options...
kenrbnsn Posted July 4, 2008 Share Posted July 4, 2008 Please read the manual page for the mail() function. The fifth parameter has nothing to do with sending "comments". Ken Quote Link to comment https://forums.phpfreaks.com/topic/113224-php-script-help/#findComment-581754 Share on other sites More sharing options...
compguru910 Posted July 4, 2008 Share Posted July 4, 2008 Here, this might help more. I pulled this out of a script I use. It doesnt send a reply message, but, it definately sends the message to you. So all you need to do is make a predefined message to go to the end user, and wala. if (isset($_POST['submit'])) { print "Post detected"; if (!$_POST['name']) { print "<p>You must enter your name</p>"; } if (!$_POST['email']) { print "<p>You must enter your email</p>"; } if (!$_POST['phone']) { print "<p>You must enter your phone number</p>"; } if ($_POST['name'] && $_POST['email'] && $_POST['phone'] && $_POST['comments']) { $email = $_POST['email']; $name = $_POST['name']; $phone = $_POST['phone']; $date = date('g:i a l F j Y'); $body = "Comment Sent By $name \n$email \n$phone \nat $date\nComment: $comments"; mail('[email protected]','Comment',$body); } } Quote Link to comment https://forums.phpfreaks.com/topic/113224-php-script-help/#findComment-581822 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.