简体   繁体   中英

Using Swiftmailer in local dev/mac with gmail, not working

I'm using swiftmailer- um... let me rephrase- trying to use swiftmailer! I am on MAC OSX, using gmail with my email client, apple mail. I am developing in a local environment so nothing is live. I should also mention that this is all in a MAMP stack (Mac, Apache, MySQL, php). The swift mailer lib is in htdocs (my root folder).

I've tried every variation I've seen online with my swiftmailer code and setting up ports with my email client, all to no avail. I am not getting any errors in my log either even though they are on, so I have nothing to go off of.

I have an html form where the user puts their email. Once submitted, that information should be sent to the swift mailer script (email.php) and then a message should be sent to the user. You see this process all the time when you sign up for things, except with me this isn't a sign up.

I will detail part of the html page below, followed by the swiftmailer script.

<div class="col-md-4">
<div class="div1">
<h2>Step 6</h2><p>Email: REQUIRED </p>   
<input type="text" id="email" name="email" class="form-control" placeholder="kookmeyer@gmail.com"></br>
</div>
</div>
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-4">
<div class="submit">
<form action="email.php">
<button type="submit" class="btn btn-primary btn-lg btn-block" name="submit" >Submit</button>
</form>

And now the swiftmailer code

<?php

require_once 'lib/swift_required.php';

//Pass it as a parameter when you create the message
$message = Swift_Message::newInstance();
$message->setSubject('My subject');
$message->setFrom(array('email@gmail.com' => 'No Reply'));
$message->setTo(array('email@gmail.com' => 'My Name'));

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('username@gmail.com')->setPassword('password');
//Supposed to allow local domain sending to work from what I read
$transport->setLocalDomain('[127.0.0.1]');
$mailer = Swift_Mailer::newInstance($transporter);
//Send the message
$result = $mailer->send($message);

?>

Any help would be extremely valuable at this point. Much thanks in advance! -Dan

First of all, your HTML and your PHP don't seem to be integrated to work together, so I will assume you're just testing your PHP file with test email addresses. In other words you don't need to display your HMTL form in your question.

Secondly, your code will not work no matter what because you have an error here:

$mailer = Swift_Mailer::newInstance($transporter);

Your object name is $transport not $transporter .

If you have no warnings, notices and error messages when running your script, enable them by inserting this code at the top of your PHP file. This will override whatever setting you have in your php.ini file.

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

More details on error reporting here: http://php.net/manual/en/function.error-reporting.php

Also read carefully the Swiftmailer doc on sending emails and check that your PHP installation has the required functions available.

The errors messages, if any, should already point you in the right direction. If you can't resolve them, check back here with the output of your errors, warnings and notices. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM