Note that there are some explanatory texts on larger screens.

plurals
  1. POScript using Swiftmailer to SMTP works on localhost, but not when script accessed through IP address
    text
    copied!<p>I have a form that uses a PHP script to insert data into a MySQL DB and then respond with a confirmation email with those same details via Swiftmailer. The script is below.</p> <p>When accessed locally, the script both enters the data and sends the confirmation email via Swiftmailer thru a remote SMTP (gmail) . I.E. When using the form through localhost:XXXXXX/MyCoolSignupPage.php in the browser on the local server, everything works great.</p> <p>However, when called remotely over the internet (i.e. when I go to <a href="http://mywebsite.com/mycoolsignuppage.php" rel="nofollow">http://mywebsite.com/mycoolsignuppage.php</a>), the form inserts the data into the DB but Swiftmailer does not send the response email and there is no echo "success".</p> <p>To note, A) The Swiftmailer library is in the root. Probably not best practice. B) the site is in Inetpub/ I'm using IIS and C) no inbound mail ports are open. </p> <p>Both cURL and Open_SSL are not commented out. </p> <p>Here is the code: </p> <pre><code>&lt;?php require 'db.php'; foreach($_POST as $key =&gt; $value){ $$key = $value; } $stm = $db-&gt;prepare("INSERT INTO signup ( email, firstname, lastname, acountnumber, couponcode ) VALUES ( :email, :firstname, :lastname, :accountnumber, :couponcode )"); $stm-&gt;bindParam(":email", $email); $stm-&gt;bindParam(":firstname", $firstname); $stm-&gt;bindParam(":lastname", $lastname); $stm-&gt;bindParam(":accountnumber", $accountnumber); $stm-&gt;bindParam(":couponcode", $couponcode); $stm-&gt;execute(); require_once 'swiftmailer/lib/swift_required.php'; $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl") -&gt;setUsername('company@email.com') -&gt;setPassword('difficultpassword'); $content = ' &lt;h3&gt;Hello, '.$firstname.'! Here are your registration details.&lt;/h3&gt; &lt;table&gt; &lt;tr&gt; &lt;th align="left"&gt;Full Name:&lt;/th&gt; &lt;td&gt;'.$firstname.' '.$lastname.'&lt;/td&gt; &lt;/tr&gt; &lt;th align="left"&gt;Account Number:&lt;/th&gt; &lt;td&gt;'.$accountnumber.'&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th align="left"&gt;Coupon Code:&lt;/th&gt; &lt;td&gt;'.$couponcode.'&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;/table&gt; &lt;p&gt;Signed,&lt;/p&gt; &lt;p&gt;The Company/p&gt; '; $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance('Email Subject') -&gt;setFrom(array('company@email.com' =&gt; 'The Company')) -&gt;setTo(array($email =&gt; $email)) -&gt;setBody($content, 'text/html'); $numSent = $mailer-&gt;send($message); printf("Sent %d messages\n", $numSent); echo "success"; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload