Page 1 of 1

Newbie to SwiftMail()

Posted: Thu Mar 11, 2010 1:35 am
by GrahamG
I have been asked by my host server provider to change from PHPmailer to SwiftMailer which I have started.

I have tried a basic "test" using:

Code: Select all

 
// Include this needed file
require_once 'lib/swift_required.php';
 
// Start the mailer
$mailer = new Swift_Mailer(new Swift_MailTransport());
 
// Create a message
// SYNTAX is $message = Swift_Message::newInstance('SUBJECT', 'MESSAGE', 'text/html')
// ->setFrom(array('from@email.address' => 'Graham Gillett'))
// ->setTo(array('to@email.address' => 'Test Person'));
$message = Swift_Message::newInstance('Enquiry from website', 'MESSAGE', 'text/html')
->setFrom(array('info@voxnational.co.za' => 'Graham'))
->setTo(array('$email_address' => $first_name));
 
// Send it
$mailer->send($message);
 
And this works well, and fast, BUT... when it comes to get the values from the enquiry form using say:

Code: Select all

 
// get variables
$company = $_POST["Company"];
$last_name = $_POST["Last_Name"];
$first_name = $_POST["First_Name"];
$email_address = $_POST["email"];
$telephone_number = $_POST["Contact_Telephone"];
$cellphone_number = $_POST["Contact_Cellphone"];
 
I can't "plug-in" the variables into the test above. Anyone any idea ???

Re: Newbie to SwiftMail()

Posted: Thu Mar 11, 2010 4:24 am
by Weirdan
GrahamG wrote:I can't "plug-in" the variables into the test above.
And what is it exactly that you can't do? Or, rather, what are you trying to do?

Re: Newbie to SwiftMail()

Posted: Thu Mar 11, 2010 4:32 am
by GrahamG
The form creates the "names" Company, First_Name, Last_Name etc. and these are (or should be) passed over to the email handler, as in my posting:
// get variables
$company = $_POST["Company"];
$last_name = $_POST["Last_Name"];
$first_name = $_POST["First_Name"];
$email_address = $_POST["email"];
$telephone_number = $_POST["Contact_Telephone"];
$cellphone_number = $_POST["Contact_Cellphone"];

When I come to use say $email_address in:
$message = Swift_Message::newInstance('Enquiry from website', 'MESSAGE', 'text/html')
->setFrom(array('info@voxnational.co.za' => 'Graham'))
->setTo(array('$email_address' => $first_name));

It does not work.

Re: Newbie to SwiftMail()

Posted: Thu Mar 11, 2010 4:36 am
by Weirdan
GrahamG wrote:When I come to use say $email_address in:
[...]
It does not work.
you need to remove single quotes (') around the $email_address in there.

Re: Newbie to SwiftMail()

Posted: Thu Mar 11, 2010 4:51 am
by GrahamG
Many thanks for the speedy help.

Actually I have thought of that and have tried it with single and double quotes and wothout quotes and it still doen't seem to work. I will try again now.

Many thanks. I'll keep the posting if same occurs.:)

Re: Newbie to SwiftMail()

Posted: Thu Mar 11, 2010 5:01 am
by GrahamG
I don't believe it. IT WORKED.

Honestly I tried ' and " and no quotes and nothing worked. Perhaps server problems.

Many thanks.

Re: Newbie to SwiftMail()

Posted: Thu Mar 11, 2010 9:49 am
by GrahamG
OK. Now I have it working do I need to use a STOP or DISCONNECT command for the SMTP or Swiftmailer() ?

Re: Newbie to SwiftMail()

Posted: Mon Aug 16, 2010 9:34 am
by johnshep
I needed this code. Had the same problem.