macwise Posted September 18, 2010 Share Posted September 18, 2010 I am working on a phpmailer script that sends an order confirmation email to the customer AND the client at the same time. If I have the customer email and client email set both to the originating domain's email addresses (myname@myserver.com), then it sends fine. However, if I try to send to an outside mail server (eg. someone@gmail.com), I get the following errors: SMTP -> FROM SERVER:220 myserver.com ESMTP Exim 4.63 Sat, 18 Sep 2010 15:08:21 -0700 SMTP -> FROM SERVER: 250 myserver.com Hello localhost [127.0.0.1] 250-SIZE 52428800 250-PIPELINING 250-AUTH LOGIN PLAIN 250-STARTTLS 250 HELP SMTP -> FROM SERVER:250 OK SMTP -> FROM SERVER:250 Accepted SMTP -> FROM SERVER: SMTP -> ERROR: RCPT not accepted from server: SMTP Error: The following recipients failed: someone@gmail.com Message could not be sent. Mailer Error: SMTP Error: The following recipients failed: someone@gmail.com SMTP server error: I'm not sure what's going on here. Any SMTP or phpmailer geniuses here that can shed some light on what needs to happen here for this to send to any address? Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 18, 2010 Share Posted September 18, 2010 So IF I am following correctly what you say, your sending mail from your local server right? if not you can stop reading What i did to sent email outside my network, was open php.ini and changed the default fields 'smtp.localhost or something it's called' in to SMTP = smtp.YOUR-ISP-should be placed here.com. Just ask your ISP what the smtp is. [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = smtp.YOUR-ISP-should be placed here.com ; http://php.net/smtp-port smtp_port = 25 But I must say, my emails sent straight form my computers arrive in the spam ofcourse since i dont have a correct emailaddress. But on your host that should be no problem, atleast it's not for me. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 18, 2010 Share Posted September 18, 2010 He isn't using mail(), he's using PHPMailer. Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 18, 2010 Share Posted September 18, 2010 oh hehe, well atleast i warned him to stop reading (for a different reason lols) Quote Link to comment Share on other sites More sharing options...
macwise Posted September 18, 2010 Author Share Posted September 18, 2010 Interesting you should suggest this, though. I've wondered if it's something like this. I added a reply to address in case the server was rejecting it for that reason. I've also removed my HTML doctype declarations et. al. in hopes that maybe the formatting was incorrect for Gmail. No go. Maybe the originating server is announcing itself as localhost or some such? I would expect that the phpmailer would handle that behind the scenes, but I'm really unfamiliar with the whole server side mail stuff past the basic contact form. Anything else I can check/test/experiment with? Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 19, 2010 Share Posted September 19, 2010 I have never used phpmailer I assume it's a class or something. Maybe there is a line inside there that say ini_set which I did in php.ini , and you should put your host stuff in there? But this is just a wild guess. Quote Link to comment Share on other sites More sharing options...
macwise Posted September 19, 2010 Author Share Posted September 19, 2010 Ok, I really didn't want to have to resort to this, but you people have left me no choice. Get ready for.... THE FULL CODE FILE!!!! (truncated and concatenated for some semblance of brevity) Can you see anything that would point to this thing failing? class.phpmailer.php AND class.smtp.php are both stock 5.1 files. My site is hosted on MediaTemple GridServer. That may be playing some part in this problem And finally, I can get these to send intermittently, only VERY intermittently. No idea what the difference is. Time? New session? Both? Neither? I dunno. <?php if (!isset($_COOKIE["Customer_Info_"])) { } //header("Location: ../confirmation/index.php?message=sent"); require("class.phpmailer.php"); //Contents of form $Customer_Name=$_POST['Customer_Name']; $Title=$_POST['Title']; $Organization=$_POST['Organization']; $Street_Address=$_POST['Street_Address']; $Street_Address_2=$_POST['Street_Address_2']; $City=$_POST['City']; $State=$_POST['State']; $Zip_Code=$_POST['Zip_Code']; $Country=$_POST['Country']; $Work_Phone=$_POST['Work_Phone']; $Email=$_POST['Email']; $Purhcase_Order=$_POST['Purhcase_Order']; $Shipping_Street_Address=$_POST['Shipping_Street_Address']; $Shipping_Address_2=$_POST['Shipping_Address_2']; $Shipping_City=$_POST['Shipping_City']; $Shipping_State=$_POST['Shipping_State']; $Shipping_Zip=$_POST['Shipping_Zip']; $Shipping_Country=$_POST['Shipping_Country']; $Shipping_Method=$_POST['Shipping_Method']; $shipping_standard=$_POST['shipping_standard']; $Instructions=stripslashes(htmlspecialchars($_POST['Instructions'], ENT_QUOTES)); $ipaddress=$_POST['ipaddress']; $productOrdered=$_POST['productOrdered']; $productOrdered2=str_replace('™', chr(153), $productOrdered); if($Customer_Name != ""){ setcookie("Customer_Info[Name]", $Customer_Name, time()+108000, "/", ".mydomain.com"); } if($Title != ""){ setcookie("Customer_Info[Title]", $Title, time()+108000, "/", ". mydomain.com"); } if($Organization != ""){ setcookie("Customer_Info[Organization]", $Organization, time()+108000, "/", ". mydomain.com"); } if($Street_Address != ""){ setcookie("Customer_Info[street_Address]", $Street_Address, time()+108000, "/", ". mydomain.com"); } if($Street_Address_2 != ""){ setcookie("Customer_Info[street_Address_2]", $Street_Address_2, time()+108000, "/", ". mydomain.com"); } if($City != ""){ setcookie("Customer_Info[City]", $City, time()+108000, "/", ". mydomain.com"); } if($State != ""){ setcookie("Customer_Info[state]", $State, time()+108000, "/", ". mydomain.com"); } if($Zip_Code != ""){ setcookie("Customer_Info[Zip_Code]", $Zip_Code, time()+108000, "/", ". mydomain.com"); } if($Country != ""){ setcookie("Customer_Info[Country]", $Country, time()+108000, "/", ". mydomain.com"); } if($Work_Phone != ""){ setcookie("Customer_Info[Work_Phone]", $Work_Phone, time()+108000, "/", ". mydomain.com"); } if($Email != ""){ setcookie("Customer_Info[Email]", $Email, time()+108000, "/", ". mydomain.com"); } if($Shipping_Street_Address != ""){ setcookie("Customer_Info[shipping_Street_Address]", $Shipping_Street_Address, time()+108000, "/", ". mydomain.com"); } if($Shipping_Address_2 != ""){ setcookie("Customer_Info[shipping_Address_2]", $Shipping_Address_2, time()+108000, "/", ". mydomain.com"); } if($Shipping_City != ""){ setcookie("Customer_Info[shipping_City]", $Shipping_City, time()+108000, "/", ". mydomain.com"); } if($Shipping_State != ""){ setcookie("Customer_Info[shipping_State]", $Shipping_State, time()+108000, "/", ". mydomain.com"); } if($Shipping_Zip != ""){ setcookie("Customer_Info[shipping_Zip]", $Shipping_Zip, time()+108000, "/", ". mydomain.com"); } if($Shipping_Country != ""){ setcookie("Customer_Info[shipping_Country]", $Shipping_Country, time()+108000, "/", ". mydomain.com"); } if($Shipping_Method != ""){ setcookie("Customer_Info[shipping_Method]", $Shipping_Method, time()+108000, "/", ". mydomain.com"); } if($shipping_standard != ""){ setcookie("Customer_Info[shipping_standard]", $shipping_standard, time()+108000, "/", ". mydomain.com"); } if ((strlen(preg_replace("/&[a-z]{2,5};/i",'X',$Customer_Name)) > 1) && (strlen($Customer_Name) > 1)) { $whitespaceposition = strrpos($Customer_Name," ",1); $nameTrimmed = substr($Customer_Name, 0, $whitespaceposition); } $sender = "me@mydomain.com"; $recipient = "me@myOTHERdomain.com"; $subject = "CLIENT's Order Form"; $message = "Customer name: $Customer_Name \n\r Title: $Title \n\r Organization: $Organization \n\r Phone Number: $Work_Phone \n\r Email: $Email \n\r Street Address: $Street_Address \n\r Street Address 2: $Street_Address_2 \n\r City: $City \n\r State: $State \n\r Zip Code: $Zip_Code \n\r Country: $Country \n\r\n\r Purhcase Order #: $Purhcase_Order \n\r\n\r Shipping Address: $Shipping_Street_Address \n\r Shipping Address 2: $Shipping_Address_2 \n\r Shipping City: $Shipping_City \n\r Shipping State: $Shipping_State \n\r Shipping Zip: $Shipping_Zip \n\r Shipping Country: $Shipping_Country \n\r Expedited Shipping?: $shipping_expedited \n\r Standard Shipping?: $shipping_standard \n\r Shipping Country: $Shipping_Country \n\r Instructions: $Instructions \n\r IP Address: $ipaddress"; $mail = new phpmailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->CharSet = "UTF-8"; $mail->Host = "localhost"; // specify main and backup server $mail->SMTPAuth = false; // turn on or off SMTP authentication $mail->Username = $user; // SMTP username $mail->Password = $passwd; // SMTP password $mail->From = $sender;//$from; //name listed in from field $mail->FromName = 'FROM THE CLIENT; $mail->AddAddress($recipient); //the name (e.g. Jack) will be set in address book $mail->AddAddress($Email); // Add customer as a recipient of this email $mail->AddReplyTo('me@myOTHERdomain.com, 'NO REPLY'); $mail->SMTPDebug = 2; $mail->WordWrap = 50; // set word wrap to 50 characters $mail->IsHTML(true); // set email format to HTML $mail->Subject = $subject; $htmlBody = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; $htmlBody .= '<html xmlns="http://www.w3.org/1999/xhtml">'; $htmlBody .= '<head>'; $htmlBody .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; $htmlBody .= '<meta http-equiv="X-UA-Compatible" content="IE=7" />'; $htmlBody .= '<title>Online Order</title>'; $htmlBody .= '</head>'; $htmlBody .= '<body style="font-family: \'Helvetica Neue\', Helvetica, \'Lucida Grande\', Verdana, sans-serif; font-size: 14px;">'; ?> {chopped here so this stays short...er} <?php $htmlBody .= '</div>'; $htmlBody .= '</body>'; $htmlBody .= '</html>'; $mail->Body = $htmlBody; $mail->AltBody = $message; //this will be interesting to figure out /* foreach ($_COOKIE["Product_ID_"] as $name => $cartItem) { setcookie("Product_ID_[$name]", "", time() - 3600, "/", ".mydomain.com"); } setcookie("Product_ID_", "", time() - 3600, "/", ". mydomain.com"); */ if(!$mail->Send()) //add code to tell what the error was here { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; //exit; really exit here? I don't think so } ?> Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 19, 2010 Share Posted September 19, 2010 I think this is the part you should look at: It should have other values i bet than localhost $mail = new phpmailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->CharSet="UTF-8"; $mail->Host = "localhost"; // specify main and backup server $mail->SMTPAuth = false; // turn on or off SMTP authentication $mail->Username = $user; // SMTP username $mail->Password = $passwd; // SMTP password Quote Link to comment Share on other sites More sharing options...
macwise Posted September 19, 2010 Author Share Posted September 19, 2010 Thanks for all your help, fortnox007. I have played with that section of code for three days now to no avail. But, after researching yet further, it was finally my 437th google query that brought a reprieve. Turns out it is either latency, slow response from outside mail servers (yahoo, google, etc.) or both. I added the following line to my file, and all seems well now. I suppose this will fix 99% of my problems. $mail->Timeout = 120; // set longer timeout for latency or servers that take a while to respond So the previously posted mail section now looks like this: $mail = new phpmailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->Timeout = 120; // set longer timeout for latency or servers that take a while to respond $mail->CharSet="UTF-8"; $mail->Host = "localhost"; // specify main and backup server $mail->SMTPAuth = false; // turn on or off SMTP authentication $mail->Username = $user; // SMTP username $mail->Password = $passwd; // SMTP password For anyone that cares, timeout is set to a default of 10 seconds in the class.phpmailer.php file. Quote Link to comment 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.