how can I get a message(header + body) in variable?

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
chlorid
Forum Newbie
Posts: 5
Joined: Wed Aug 27, 2008 4:22 am

how can I get a message(header + body) in variable?

Post by chlorid »

how can I get a message(header + body) in variable?

I need to write it in a folder "sent"
But now i'm working with Swift Mailer and I need to get full message of mail
I wrote:
$smtpServer='smtp.mydomain.ua';
$subject=$this->getRequestParameter('subject');
$to=$this->getRequestParameter('to');
$text=$this->getRequestParameter('text');

$swift= new Swift(new Swift_Connection_SMTP($smtpServer));
$message= new Swift_Message($subject,$text);
$swift->send($message,$to,'svalera@mydomain.ua');
==> Here I need to get formed message as text
Sorry for my bad english
chlorid
Forum Newbie
Posts: 5
Joined: Wed Aug 27, 2008 4:22 am

Re: how can I get a message(header + body) in variable?

Post by chlorid »

I'm use SMTP mode
Trance-formation
Forum Newbie
Posts: 11
Joined: Tue Jul 17, 2007 6:31 am

Re: how can I get a message(header + body) in variable?

Post by Trance-formation »

as you have $subject and $text existing as variables already, can you not just concatonate them to suit your purposes?
chlorid
Forum Newbie
Posts: 5
Joined: Wed Aug 27, 2008 4:22 am

Re: how can I get a message(header + body) in variable?

Post by chlorid »

Trance-formation wrote:as you have $subject and $text existing as variables already, can you not just concatonate them to suit your purposes?
but as the same header?
and specifically please
TheMatrixDuck
Forum Newbie
Posts: 4
Joined: Fri Sep 12, 2008 12:49 pm

Re: how can I get a message(header + body) in variable?

Post by TheMatrixDuck »

ok... here is what was happening on our system:
This ended up being a MS Exchange setup problem.
The to address was setup as a distribution list on our email server so the inbound email would be sent to three people. Exchange was showing that the email was being received by the server, it just wasn't being propagated through the distribution list. When I send the email to
one person, it goes through. My exchange admin is working on the problem.
Here is the final code I used to send the email: (to one person)
Hope it helps anyone solve their problems.


<!--------------------------------------------------------------------------
ContactUSMail.php
php Script to send email to WebAdmin where it will be routed
manually.
Created 9/16/08 by Dennis Dean
---------------------------------------------------------------------------->

<?php
require_once "\program files\php\swiftlib\lib\swift.php";
require_once "\program files\php\swiftlib\lib\swift\Connection\SMTP.php";
error_reporting(E_ALL); ini_set('display_errors', true);

// gather required information
$wTo = "WebContact@4pct.com";
$wFrom = $_POST["Name"];
$wSubject = "Website inquiry from ". $wFrom. ". Please contact us.";
$wCompany = $_POST["Company"];
$wTitle = $_POST["Title"];
$wWorkPhone = $_POST["WorkPhone"];
$wCellPhone = $_POST["CellPhone"];
$wEmail = $_POST["Email"];
$wComments = $_POST["Comments"];

// assign to body of mail message
$Mailbody = "A website user has requested contact.\n";
$Mailbody .= "Here is their contact information : \n\n";
$Mailbody .= "Name: " . $wFrom. "\n";
$Mailbody .= "Company: " . $wCompany. "\n" ;
$Mailbody .= "Title: " . $wTitle. "\n";
$Mailbody .= "Work: " . $wWorkPhone. "\n";
$Mailbody .= "Cell: " . $wCellPhone. "\n" ;
$Mailbody .= "email: " . $wEmail. "\n\n";

// retrieve the checkbox values...
if (isset($_POST["chkContractor"])) {
$Mailbody .= $wFrom. " is a contractor.\n";
}
if (isset($_POST["chkHomeowner"])) {
$Mailbody .= $wFrom. " is a homeowner.\n";
}
if (isset($_POST["chkDesigner"])) {
$Mailbody .= $wFrom. " is a designer.\n";
}
if (isset($_POST["chkBuilder"])) {
$Mailbody .= $wFrom. " is a builder.\n";
}

$Mailbody .= "\nComments: \n". $wComments."\n";

try {
//Start Swift
$swift = new Swift(new Swift_Connection_SMTP("PCTEMAIL1.pctinternal.net"));

//Create the message
$message = new Swift_Message($wSubject, $Mailbody);

//Now check if Swift actually sends it Send(Message, Recipient, From)
$swift->send($message, new Swift_Address("BiancaRuelig@4pct.com"), new Swift_Address("WebAdmin@4pct.com","WebAdmin-NO REPLY"));

} catch (Swift_ConnectionException $e) {
echo "There was a problem communicating with SMTP: " . $e->getMessage();
} catch (Swift_Message_MimeException $e) {
echo "There was an unexpected problem building the email:" . $e->getMessage();

$swift->disconnect();
}

// end php send email
?>
Post Reply