Page 1 of 1

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

Posted: Wed Aug 27, 2008 8:39 am
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

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

Posted: Thu Aug 28, 2008 1:35 am
by chlorid
I'm use SMTP mode

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

Posted: Fri Aug 29, 2008 1:13 pm
by Trance-formation
as you have $subject and $text existing as variables already, can you not just concatonate them to suit your purposes?

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

Posted: Tue Sep 02, 2008 6:09 am
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

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

Posted: Tue Sep 16, 2008 1:05 pm
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
?>