August 9, 201115 yr Hi All, I have a php script set up to send an email from a contact form. I use it on a number of different sites and it's always worked. I've just dropped it into another site and tested it and now it's returning an error. I don't know php that well so I've tried a few things and it's made no difference and I'm loathed to mess about too much in case I end up with it completely trashed. Any help anyone can give would be truly appreciated. Thanks Andy The error is: [b]Warning[/b]: mail()[funtion.mail]: SMTP server response:554 mail server permanently rejected message (#5.3.0) in [b]D:\Hosting\8209774\html\sendemail.php[/b] on line [b]179[/b] The php script is: <?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $email_address = $_POST['email_address']; $notes = $_POST['notes']; $subject = $_POST['subject']; $telephone_number = $_POST['telephone_number']; if (eregi('http:', $notes)) { die ("Do NOT try that! ! "); } if(!$email_address == "" && (!strstr($email_address,"@") || !strstr($email_address,"."))) { echo "<h2>Use Back - Enter valid e-mail</h2>\r\n"; $badinput = "<h2>Feedback was NOT submitted</h2>\r\n"; echo $badinput; die ("Go back! ! "); } if(empty($name) || empty($telephone_number) || empty($email_address) || empty($notes )) { echo "<h2>Use Back - fill in all fields</h2>\r\n"; die ("Use back! ! "); } $todayis = date("l, F j, Y, g:i a") ; $attn = $attn ; $subject = $subject; $subject = $attn; $telephone_number = $telephone_number; $notes = stripcslashes($notes); $message = " Enquiry Subject: $subject \r\n Message: $notes \r\n From: $name ($email_address)\r\n Telephone: $telephone_number \r\n $todayis [EST] \r\n "; $from = "From: $email_address \r\n"; mail("info@pageoneofgoogle.co.uk", $subject, $message, $from); ?> <p align="left"> Thank You <b><?php echo $name ?></b> ( <?php echo $email_address ?> ) for your message regarding <b><?php echo $subject ?></b> <br /> <br /> Your enquiry reads as follows:<br /><br /> <i><?php $notesout = str_replace("\r", "<br/>", $notes); echo $notesout; ?></i> <br /><br /> Your messgae was sent: <?php echo $todayis ?>
August 9, 201115 yr Author Ok so the code is something I downloaded a few months ago and it's always worked without any problem, this is the first time it's not worked. Is the code that bad then? What is it, old school coding or something. I'd love to build one from scratch but it feels like a step too far for my knowledge of php. So does the error mean that the form is busted, the code is busted or all of the above? Can I fix the coding or am I looking at an entirely new script?
August 9, 201115 yr It could be the way you’re sending the email; try using the function in this http://www.webdesignerforum.co.uk/topic/52312-how-to-send-html-emails-with-multiple-attachments-in-php/, you shouldn’t need to change much of your own code to implement it into your script. Other than that I don’t really know what to suggest, this error is normally caused when sending dodgy attachments.
August 9, 201115 yr Ok so the code is something I downloaded a few months ago and it's always worked without any problem, this is the first time it's not worked. Is the code that bad then? What is it, old school coding or something. I'd love to build one from scratch but it feels like a step too far for my knowledge of php. So does the error mean that the form is busted, the code is busted or all of the above? Can I fix the coding or am I looking at an entirely new script? You can try my contact form if you like My Contact Form Edited August 9, 201115 yr by webdesigner93
August 10, 201115 yr Author Thanks for the replies so far guys, I was working on rewriting the code based on something simple but more up to date. So I wrote it, inserted it, uploaded it and guess what......yes I'm still getting the same errors. I can't understand why though, there is nothing wrong with this script as far as I can see. Any thoughts before I make my third attempt? The error throws up something about qmail which doesn't make sense, because I have already used my first version of the form on the same hosting account in exactly the same way and it works fine. Seriously confusing! Here's the code for the new script: <?php $Email_from = $_POST['contact_name']; $Email_to = "info@pageoneofgoogle.co.uk"; $Subject = $_POST['contact_company_name']; $Telephone = $_POST['contact_tel']; $Name = $_POST['contact_name']; $Email = $_POST['contact_email']; $Message = trim(stripslashes($_POST['contact_message'])); $Body = ""; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; /* send email */ $send = mail($Email_to, $Subject, $Body, "From: <$Email_from>"); /* if it's successful */ if ($send) { print " <meta http-equiv=\"refresh\" content=\"0;URL=index.php\"> "; } ?>
August 10, 201115 yr Author Firstly, huge ouch at that contact form code! Thanks very much, I did say I wasn't a php pro Anyways, the error is fairly serious and I probably wouldn't keep trying to send your email at the mo. - I onloy ever got that when I accidently tried to attach an exe to an email message. There is no attachments or exe files or anything on this page. Have you tried setting different headers and/or using SMTP auth to send you mails? I don't what this means or how to do it. Can you explain a bit more ta.
August 10, 201115 yr Author It could be the way you’re sending the email; try using the function in this http://www.webdesignerforum.co.uk/topic/52312-how-to-send-html-emails-with-multiple-attachments-in-php/, you shouldn’t need to change much of your own code to implement it into your script. Other than that I don’t really know what to suggest, this error is normally caused when sending dodgy attachments. Thanks for the response. I've looked at your code, where is the actual message send function? Is it the code right at the top? The rest of it looks like content (most of it is over my head!)
August 10, 201115 yr Author You can try my contact form if you like My Contact Form Thanks for this, but I want to try and understand why it's not working and how to fix it. My mind isn't satisfied unless I can understand and solve the problem or know why I can't solve it! If I get no joy in trying to resolve it, looking at a new script will be the next step. Thanks again.
August 10, 201115 yr The function is found right at the bottom of my guide, you can paste it in above your code. Here is an example of how you could implement it into your script: // Paste the Email function here $Subject = $_POST['contact_company_name']; $Telephone = $_POST['contact_tel']; $Name = $_POST['contact_name']; $Email = $_POST['contact_email']; $Message = trim(stripslashes($_POST['contact_message'])); $Body = ""; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; $Body .= "Telephone: "; $Body .= $Telephone; $Body .= "\n"; $Body .= "Their contact email: "; $Body .= $Email; $Body .= "\n"; /* send email */ $send = Email("info@pageoneofgoogle.co.uk", // Your email adress "Page One Of Google", // Your name "contact@pageoneofgoogle.co.uk", // Using your domain to avoid it being interpreted as spam $Name, // Their name "", // CC, left blank because you don't need "", // BCC, left blank because you don't need $Subject, // Subject $Body, // Message "", // Attachments, left blank because you don't need "", // Priority, Left blank for normal "plain"); // Type is set to plain text /* if it's successful */ if ($send) { print " <meta http-equiv=\"refresh\" content=\"0;URL=index.php\"> "; } You can adjust it where necessary, but you should get the basic idea, hope it helps
August 10, 201115 yr Author Ok, so good news and bad news! The good news is, using your function I no longer get the error message, and I also receive an email which is great. The bad news is that the email doesn't contain anything, just three lines of text: Message: Telephone: Their contact email: But with nothing in them. I am wondering if it is simply a case of me having different variable names to those in your function and so should I change the variable names in the function and see what happens? Or are the names in the function not related to the names in my script below the function? It's gotta be something like that right? Different named variables? The great news is I feel like I'm getting somewhere
August 10, 201115 yr It looks like your $_POST’s are empty, you could try it with your original script if it makes it easier: // Paste the Email function here like before $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $email_address = $_POST['email_address']; $notes = $_POST['notes']; $subject = $_POST['subject']; $telephone_number = $_POST['telephone_number']; if (eregi('http:', $notes)) { die ("Do NOT try that! ! "); } if(!$email_address == "" && (!strstr($email_address,"@") || !strstr($email_address,"."))) { echo "<h2>Use Back - Enter valid e-mail</h2>\r\n"; $badinput = "<h2>Feedback was NOT submitted</h2>\r\n"; echo $badinput; die ("Go back! ! "); } if(empty($name) || empty($telephone_number) || empty($email_address) || empty($notes )) { echo "<h2>Use Back - fill in all fields</h2>\r\n"; die ("Use back! ! "); } $todayis = date("l, F j, Y, g:i a") ; $attn = $attn ; $subject = $subject; $subject = $attn; $telephone_number = $telephone_number; $notes = stripcslashes($notes); $message = " Enquiry Subject: $subject \r\n Message: $notes \r\n From: $name ($email_address)\r\n Telephone: $telephone_number \r\n $todayis [EST] \r\n "; Email("info@pageoneofgoogle.co.uk", // Your email adress "Page One Of Google", // Your name "contact@pageoneofgoogle.co.uk", // Using your domain to avoid it being interpretated as spam $name, // Their name "", // CC, left blank because you don't need "", // BCC, left blank because you don't need $subject, // Subject $message, // Message "", // Attachments, left blank because you don't need "", // Priority, Left blank for normal "plain"); // Type is set to plain text ?> <p align="left"> Thank You <b><?php echo $name ?></b> ( <?php echo $email_address ?> ) for your message regarding <b><?php echo $subject ?></b> <br /> <br /> Your enquiry reads as follows:<br /><br /> <i><?php $notesout = str_replace("\r", "<br/>", $notes); echo $notesout; ?></i> <br /><br /> Your messgae was sent: <?php echo $todayis ?>
August 11, 201115 yr Author It looks like your $_POST’s are empty, you could try it with your original script if it makes it easier: I can't really use the old script as the form isn't the same as the new one I'm using. I just don't understand what would be causing the variable to be empty. I can't see anything wrong with the form (code below) and your script mails it through ok just without any content. I've been scouring the net trying to understand what causes empty variables/arrays but I've found no definitive answer. The weird thing is that the original form and script are used for the same client but on a different domain hosted on the same hosting server and it works fine. As soon as I copy and paste it into this site it doesn't. So frustrating, as much because I'm a little clueless when it comes to php. So anyway, the form I'm using is below (just in case there is something stoopid I've neglected to do on the form) along with the script including your function. The live version of the form is at www.visionhomesltd.co.uk/make-an-enquiry.php I appreciate you trying to help me out, if I can return the favour please let me know. Andy The Form <form method="post" action="sendemail.php"> <div class="form_field"> <label for="contact_name">Name <span class="required">(required)</span></label> <input id="contact_name" type="text" name="name" /> </div> <div class="form_field end"> <label for="contact_company_name">Subject</label> <input id="contact_company_name" type="text" name="subject" /> </div> <div class="form_field"> <label for="contact_tel">Telephone Number <span class="required">(required)</span></label> <input id="contact_tel" type="tel" name="telephone_number" /> </div> <div class="form_field end"> <label for="contact_email">Email Address</label> <input id="contact_email" type="email" name="email_address" /> </div> <div class="message-field"> <label for="contact_message">Your Message <span class="required">(required)</span></label> <textarea id="contact_message" name="notes" rows="3"></textarea> </div> <input type="image" src="images/button_send_message2.png" value="Send Your Message" id="send_message" /> </form> The script and function <?php // This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License function Email($remail, $rname, $semail, $sname, $cc, $bcc, $subject, $message, $attachments, $priority, $type) { // Checks if carbon copy & blind carbon copy exist if($cc != null){$cc="CC: ".$cc."\r\n";}else{$cc="";} if($bcc != null){$bcc="BCC: ".$bcc."\r\n";}else{$bcc="";} // Checks the importance of the email if($priority == "high"){$priority = "X-Priority: 1\r\nX-MSMail-Priority: High\r\nImportance: High\r\n";} elseif($priority == "low"){$priority = "X-Priority: 3\r\nX-MSMail-Priority: Low\r\nImportance: Low\r\n";} else{$priority = "";} // Checks if it is plain text or HTML if($type == "plain"){$type="text/plain";}else{$type="text/html";} // The boundary is set up to separate the segments of the MIME email $boundary = md5(@date("Y-m-d-g:ia")); // The header includes most of the message details, such as from, cc, bcc, priority etc. $header = "From: ".$sname." <".$semail.">\r\nMIME-Version: 1.0\r\nX-Mailer: PHP\r\nReply-To: ".$sname." <".$semail.">\r\nReturn-Path: ".$sname." <".$semail.">\r\n".$cc.$bcc.$priority."Content-Type: multipart/mixed; boundary = ".$boundary."\r\n\r\n"; // The full message takes the message and turns it into base 64, this basically makes it readable at the recipients end $fullmessage .= "--".$boundary."\r\nContent-Type: ".$type."; charset=UTF-8\r\nContent-Transfer-Encoding: base64\r\n\r\n".chunk_split(base64_encode($message)); // A loop is set up for the attachments to be included. if($attachments != null) { foreach ($attachments as $attachment) { $attachment = explode(":", $attachment); $fullmessage .= "--".$boundary."\r\nContent-Type: ".$attachment[1]."; name=\"".$attachment[2]."\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment\r\n\r\n".chunk_split(base64_encode(file_get_contents($attachment[0]))); } } // And finally the end boundary to set the end of the message $fullmessage .= "--".$boundary."--"; return mail($rname."<".$remail.">", $subject, $fullmessage, $header); } $Subject = $_POST['contact_company_name']; $Telephone = $_POST['contact_tel']; $Name = $_POST['contact_name']; $Email = $_POST['contact_email']; $Message = trim(stripslashes($_POST['contact_message'])); $Body = ""; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; $Body .= "Telephone: "; $Body .= $Telephone; $Body .= "\n"; $Body .= "Their contact email: "; $Body .= $Email; $Body .= "\n"; /* send email */ $send = Email("info@pageoneofgoogle.co.uk", // Your email adress "Page One Of Google", // Your name "contact@pageoneofgoogle.co.uk", // Using your domain to avoid it being interpreted as spam $Name, // Their name "", // CC, left blank because you don't need "", // BCC, left blank because you don't need $Subject, // Subject $Body, // Message "", // Attachments, left blank because you don't need "", // Priority, Left blank for normal "plain"); // Type is set to plain text /* if it's successful */ if ($send) { print " <meta http-equiv=\"refresh\" content=\"0;URL=thank-you.html\"> "; } ?>
August 11, 201115 yr Looks like you just forgot to change the names in your form <form method="post" action="sendemail.php"> <div class="form_field"> <label for="contact_name">Name <span class="required">(required)</span></label> <input id="contact_name" type="text" name="contact_name" /> </div> <div class="form_field end"> <label for="contact_company_name">Subject</label> <input id="contact_company_name" type="text" name="contact_company_name" /> </div> <div class="form_field"> <label for="contact_tel">Telephone Number <span class="required">(required)</span></label> <input id="contact_tel" type="tel" name="contact_tel" /> </div> <div class="form_field end"> <label for="contact_email">Email Address</label> <input id="contact_email" type="email" name="contact_email" /> </div> <div class="message-field"> <label for="contact_message">Your Message <span class="required">(required)</span></label> <textarea id="contact_message" name="contact_message" rows="3"></textarea> </div> <input type="image" src="images/button_send_message2.png" value="Send Your Message" id="send_message" /> </form> Should work now
August 11, 201115 yr Author Ok so you know how sometimes you do something and it makes you feel and look like a complete plank? Well that's me! I didn't twig about the form names, so I changed them and uploaded the pages and..........it didn't work, no change, still nothing! (Did I mention I've gone bald through pulling my hair out!). So by now I'm ready to just give it up. I've tried changing all sorts of code, commenting things out, renaming things etc but to no avail. So having done a final upload to test out I thought I'd have a look at the live page to see if there was anything weird going on that was changing the coding (long shot I know). Imagine my confusion when the live page didn't reflect the page on my system. I uploaded it again (thinking I must have forgotten to) and checked it again, still the same........huh what the hell is going on. I opened up the FTP screen in dreamweaver and BANG! There was a copy of my local files and a copy of my test files on xampp! Yes you guessed it, I hadn't even been uploading the files to the same place I was checking them. No wonder nothing changed! So, having uploaded the pages to the live environment and checked it on the live environment, I sent a test email. SUCCESS!!!! Yehaw!! Yes I feel a dork, yes I shall not live it down for a fair while (please don't publicise it!). But I really just wanted to say a great big thank you for sticking with it and helping me out. Got there eventually! Muchos Grassyarse
Create an account or sign in to comment