Unknown issues sending email
Posted: Sat Feb 02, 2008 6:24 pm
Ok, here's my situation. i have setup a messaging system for a site admin to log in and send a message to the site users (much like available on phpbb or other site CMSs). It worked fine the first few tests for about a week, and it sort of stopped getting used for a little while. Now, we are going back to use it and having trouble sending email messages.
If i use if($swift->send .... ) it shows up as failing.
if i use try { $swift->send ... } it appears to be successful, however the email is not sent.
Here's the code I'm using to send: (note: this is coming out of a "log-type" table that tracks each message as it's sent)
Since I do not get any errors using try { } catch { }, i can't figure out how to find out where the problem lies. Is there a way to get the error produced when you use the if($swift->send(....)){ method? Is it possible my web host has done something to not allow messages inside of loops?
I'm using version 3.3.2 on PHP5.
here's the weird part: on the same site, i have a contact us form. it seems to be working fine. here's the code I use for that:
Thanks.
If i use if($swift->send .... ) it shows up as failing.
if i use try { $swift->send ... } it appears to be successful, however the email is not sent.
Here's the code I'm using to send: (note: this is coming out of a "log-type" table that tracks each message as it's sent)
Code: Select all
require_once("../Swift.php");
require_once("../Swift/Connection/SMTP.php");
[.. start my loop ... ]
$newMessage =& new Swift(new Swift_Connection_SMTP("localhost"));
$sender = new Swift_Address($messages->row['sender_email'],$messages->row['sender_name']);
$recipient = new Swift_Address($messages->row['recipient_email'],$messages->row['recipient_name']);
if($messages->row['message_type'] == "email"){
$message_content =& new Swift_Message($messages->row['subject'], $messages->row['message_body'], "text/html");
} else {
$message_content =& new Swift_Message($messages->row['subject'], $messages->row['message_body']);
}
try {
$newMessage->send($message_content, $recipient, $sender);
$report_append = "[".date("Y-m-d H:i:s")."] Send successful.";
$report = (empty($report)) ? $report_append : $report . "\n" . $report_append;
[ ... write $report to mysql database ... ]
} catch (Swift_ConnectionException $e) {
$report_append = "[".date("Y-m-d H:i:s")."] There was a problem communicating with SMTP: " . $e->getMessage();
$report = (empty($report)) ? $report_append : $report . "\n" . $report_append;
[ ... write $report to mysql database ... ]
} catch (Swift_Message_MimeException $e) {
$report_append = "[".date("Y-m-d H:i:s")."] There was an unexpected problem building the email:" . $e->getMessage();
$report = (empty($report)) ? $report_append : $report . "\n" . $report_append;
[ ... write $report to mysql database ... ]
}
$newMessage->disconnect();
[ ... end my loop ... ]I'm using version 3.3.2 on PHP5.
here's the weird part: on the same site, i have a contact us form. it seems to be working fine. here's the code I use for that:
Code: Select all
require_once($_SERVER['DOCUMENT_ROOT'] . "/Swift.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/Swift/Connection/SMTP.php");
[... do validation on all required fields, then ... ]
$recipients =& new Swift_RecipientList();
if($_POST['contact'] == "all"){
$recipients->addTo("addr1@domain.com", "name 1");
$recipients->addBcc("addr2@domain.com", "name 1");
$recipients->addTo("addr3@domain.com", "name 2");
$recipients->addBcc("addr4@domain.com", "name 2");
$recipients->addTo("addr5@domain.com", "name 3");
$recipients->addTo("addr6@domain.com", "name 4");
$recipients->addTo("addr7@domain.com", "name 5");
$recipients->addTo("addr8@domaincom", "name 6");
$recipients->addTo("addr9@domain.com", "name 7");
} else {
$recipients->addTo($_POST['contact']);
}
if($_POST['contact'] == "addr1@domain.com"){
$recipients->addBcc("addr2@domain.com");
}
if($_POST['contact'] == "addr3@domain.com"){
$recipients->addBcc("addr4@domain.com");
}
$email_msg = '<strong>This is my HTML email</strong>';
$subject = $_POST['subject'];
$sender = new Swift_Address($_POST['user_email'],$_POST['full_name']);
try {
$swiftContact =& new Swift(new Swift_Connection_SMTP("localhost"));
$message =& new Swift_Message($subject, $email_msg, "text/html");
if($swiftContact->send($message, $recipients, $sender)){
$_SESSION['contact_confirm'] = 'Your message has been sent.';
}
} catch (Swift_ConnectionException $e) {
$_SESSION['contact_confirm'] = '<span class="error">Error sending message.</span>';
$_SESSION['contact_confirm'] .= " There was a problem communicating with SMTP: " . $e->getMessage();
} catch (Swift_Message_MimeException $e) {
$_SESSION['contact_confirm'] = '<span class="error">Error sending message.</span>';
$_SESSION['contact_confirm'] .= " There was an unexpected problem building the email: " . $e->getMessage();
}
$swiftContact->disconnect();
header("Location: /contact/thanks/");
exit();