Newbie to SwiftMail()

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
GrahamG
Forum Newbie
Posts: 6
Joined: Tue Mar 09, 2010 10:08 am

Newbie to SwiftMail()

Post 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 ???
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Newbie to SwiftMail()

Post 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?
GrahamG
Forum Newbie
Posts: 6
Joined: Tue Mar 09, 2010 10:08 am

Re: Newbie to SwiftMail()

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Newbie to SwiftMail()

Post 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.
GrahamG
Forum Newbie
Posts: 6
Joined: Tue Mar 09, 2010 10:08 am

Re: Newbie to SwiftMail()

Post 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.:)
GrahamG
Forum Newbie
Posts: 6
Joined: Tue Mar 09, 2010 10:08 am

Re: Newbie to SwiftMail()

Post by GrahamG »

I don't believe it. IT WORKED.

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

Many thanks.
GrahamG
Forum Newbie
Posts: 6
Joined: Tue Mar 09, 2010 10:08 am

Re: Newbie to SwiftMail()

Post by GrahamG »

OK. Now I have it working do I need to use a STOP or DISCONNECT command for the SMTP or Swiftmailer() ?
johnshep
Forum Newbie
Posts: 1
Joined: Mon Aug 16, 2010 9:31 am

Re: Newbie to SwiftMail()

Post by johnshep »

I needed this code. Had the same problem.
Post Reply