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
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI'm gonna guess a fatal error is killing your script after the DB insert but before the mail gets sent. Try adding `error_reporting(E_ALL); ini_set('display_errors', 1);` at the top of your script and then run it and view the page source to see if there are any error messages towards the bottom.
      singulars
    2. CONice. Shows this: `Warning: require_once(C:\inetpub\MyCoolSite\swiftmailer\lib\swift_required.php): failed to open stream: Permission denied in C:\inetpub\MyCoolSite\Mycoolsignup.php on line 46 Fatal error: require_once(): Failed opening required 'swiftmailer/lib/swift_required.php' (include_path='.;C:\php\pear') in C:\inetpub\MyCoolsite\Mycoolsignup.php on line 46`.
      singulars
    3. COCool that's the issue, since it can't include the file you probably get an error when you try to create or use one of the swiftmailer object since the classes aren't available. The permission denied error either means the permissions on the file don't allow the web server to access the file or maybe the restriction is at the directory level. Resolving that issue should get your mail code working though.
      singulars
 

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