Coding the Gathering Data Variables

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
Forum Newbie
Posts: 1
Joined: Sat Mar 26, 2011 6:25 pm

Coding the Gathering Data Variables

Post by HummingbirdCake »


My hosting company recently started requiring SMTP, and so I have to update my contact form PHP code accordingly. I have been looking at various "newbie" topics on this board but can't seem to find one that completely answers my questions. I have the SwiftMailer code working and I am able to receive email from my contact form, but I can't figure out how to plug in the various information collecting fields. The SwiftMailer code is on top of the old PHP code I was using. Thank you for your help!!

Here is what I have:


require_once 'swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('', 25)

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance()
->setSubject(array('Hummingbird Cake Stationery Inquiry'))
->setBody('PHP Swift Mailer sent with authentication')

/* Subject and Email Variables */

$emailSubject = 'Hummingbird Cake Stationery Inquiry';
$webMaster = '';

/* Gathering Data Variables */

$emailField = $_POST['email'];
$nameField = $_POST['name'];
$addressField = $_POST['address'];
$cityField = $_POST['city'];
$countryField = $_POST['country'];
$commentsField = $_POST['comments'];
$newsletterField = $_POST['newsletter'];

$body = <<<EOD
Email: $emailField <br>
Name: $nameField <br>
Address: $addressField <br>
City: $cityField <br>
Country: $countryField <br>
Comments: $commentsField <br>
Newsletter: $newsletterField <br>

$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";

//Send the message
$result = $mailer->send($message);
Post Reply