Can anyone diagnose a failure message to one of the test!
Posted: Thu Jan 29, 2009 3:34 am
Hi,
I'd be higely grateful if someone could help me with Swift! I'm a novice so please be gentle!
We have been using the php mail command when building forms on websites, and have a HUGE problem in that emails sent from these forms are never received. Correction, they seem to be received to POP3 mail accounts when testing, but rarely ever to business (my clients) accounts (typically Microsoft Exchange)
I am wondering whether this is due to the fact we are using php mail, and so have tried to use Swift.
I have set up a test at http://www.jellybeandigital.co.uk/swift/form.php which seems to work fine (I don't get an error) but at the same time I don't receive any emails either.
So I have run the first test, and get a failure - is anyone able to either:
Interpret the failure (full text below)
Explain why the test link above might be no good (full text of scripts below)
Thanks, sorry if I'm being long-winded.
FAILURE MESSAGE
-----------------
Error: Message did not send!
Log Information
++ Log level changed to 4
++ Trying to connect...
++ Trying to connect to SMTP server at 'smtp.swiftmailer.org:25
<< 220 w3style.co.uk ESMTP Exim 4.63 Thu, 29 Jan 2009 09:16:08 +0000
>> EHLO [62.89.142.201]
<< 250-w3style.co.uk Hello [62.89.142.201] [62.89.142.201]
250-SIZE 52428800
250-PIPELINING
250-AUTH CRAM-MD5
250 HELP
++ SMTP extension 'SIZE' reported with attributes [52428800].
++ SMTP extension 'PIPELINING' reported with attributes [].
++ SMTP extension 'AUTH' reported with attributes [CRAM-MD5].
++ SMTP extension 'HELP' reported with attributes [].
>> MAIL FROM: <chris@w3style.co.uk>
<< 250 OK
>> RCPT TO: <andy@jellybeancreative.co.uk>
<< 550 relay not permitted
!! Expected response code(s) [250] but got response [550 relay not permitted]
!! Recipient 'andy@jellybeancreative.co.uk' rejected by connection.
>> RSET
<< 250 Reset OK
FORM.PHP
---------
<?php
//Display an error if something went wrong
if (!empty($_GET["error"]))
{
switch ($_GET["error"])
{
case "not_enough_info": ?>
<strong style="color: red;">You need to complete all fields marked *<strong><?php
break;
case "invalid_email": ?>
<strong style="color: red;">Please provide a valid email address</strong><?php
break;
case "upload_failed": ?>
<strong style="color: red;">The file you uploaded failed to attach, this could be a temporary problem.
Please try later.</strong><?php
break;
case "sending_failed": ?>
<strong style="color: red;">Temporary problem, please try later.</strong><?php
break;
}
}
?>
<form action="handle_form.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td class="label">Name *</td>
<td><input type="text" name="sender_name" value="" /></td>
</tr>
<tr>
<td class="label">E-mail address *</td>
<td><input type="text" name="sender_email" value="" /></td>
</tr>
<tr>
<td class="label">Title *</td>
<td><input type="text" name="comment_title" value="" /></td>
</tr>
<tr>
<td class="label">Attachment (optional)</td>
<td><input type="file" name="attachment" /></td>
</tr>
<tr>
<td colspan="2">Comment *<br />
<textarea name="comment_body" rows="10" cols="30"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
HANDLE_FORM.PHP
------------------
<?php
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["sender_name"]) || empty($_POST["sender_email"])
|| empty($_POST["comment_title"]) || empty($_POST["comment_body"]))
{
//redirect back to form
header("Location: ./form.php?error=not_enough_info"); //This should really be an absolute URL if you know it
exit();
}
//Copy into global variables
$name = $_POST["sender_name"];
$email = $_POST["sender_email"];
$title = $_POST["comment_title"];
$body = $_POST["comment_body"];
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9_\\.-]+/", $email))
{
header("Location: ./form.php?error=invalid_email");
exit();
}
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: ./form.php?error=upload_failed");
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Everything looks ok, we can start Swift
require_once "../lib/Swift.php";
require_once "../lib/Swift/Connection/SMTP.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
//Create the message to send
$message =& new Swift_Message("New comment: " . $title);
$message->attach(new Swift_Message_Part($body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
//Try sending the email
$sent = $swift->send($message, "andy@jellybeancreative.co.uk", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: ./success.php");
exit();
}
else
{
header("Location: ./form.php?error=sending_failed");
exit();
}
I'd be higely grateful if someone could help me with Swift! I'm a novice so please be gentle!
We have been using the php mail command when building forms on websites, and have a HUGE problem in that emails sent from these forms are never received. Correction, they seem to be received to POP3 mail accounts when testing, but rarely ever to business (my clients) accounts (typically Microsoft Exchange)
I am wondering whether this is due to the fact we are using php mail, and so have tried to use Swift.
I have set up a test at http://www.jellybeandigital.co.uk/swift/form.php which seems to work fine (I don't get an error) but at the same time I don't receive any emails either.
So I have run the first test, and get a failure - is anyone able to either:
Interpret the failure (full text below)
Explain why the test link above might be no good (full text of scripts below)
Thanks, sorry if I'm being long-winded.
FAILURE MESSAGE
-----------------
Error: Message did not send!
Log Information
++ Log level changed to 4
++ Trying to connect...
++ Trying to connect to SMTP server at 'smtp.swiftmailer.org:25
<< 220 w3style.co.uk ESMTP Exim 4.63 Thu, 29 Jan 2009 09:16:08 +0000
>> EHLO [62.89.142.201]
<< 250-w3style.co.uk Hello [62.89.142.201] [62.89.142.201]
250-SIZE 52428800
250-PIPELINING
250-AUTH CRAM-MD5
250 HELP
++ SMTP extension 'SIZE' reported with attributes [52428800].
++ SMTP extension 'PIPELINING' reported with attributes [].
++ SMTP extension 'AUTH' reported with attributes [CRAM-MD5].
++ SMTP extension 'HELP' reported with attributes [].
>> MAIL FROM: <chris@w3style.co.uk>
<< 250 OK
>> RCPT TO: <andy@jellybeancreative.co.uk>
<< 550 relay not permitted
!! Expected response code(s) [250] but got response [550 relay not permitted]
!! Recipient 'andy@jellybeancreative.co.uk' rejected by connection.
>> RSET
<< 250 Reset OK
FORM.PHP
---------
<?php
//Display an error if something went wrong
if (!empty($_GET["error"]))
{
switch ($_GET["error"])
{
case "not_enough_info": ?>
<strong style="color: red;">You need to complete all fields marked *<strong><?php
break;
case "invalid_email": ?>
<strong style="color: red;">Please provide a valid email address</strong><?php
break;
case "upload_failed": ?>
<strong style="color: red;">The file you uploaded failed to attach, this could be a temporary problem.
Please try later.</strong><?php
break;
case "sending_failed": ?>
<strong style="color: red;">Temporary problem, please try later.</strong><?php
break;
}
}
?>
<form action="handle_form.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td class="label">Name *</td>
<td><input type="text" name="sender_name" value="" /></td>
</tr>
<tr>
<td class="label">E-mail address *</td>
<td><input type="text" name="sender_email" value="" /></td>
</tr>
<tr>
<td class="label">Title *</td>
<td><input type="text" name="comment_title" value="" /></td>
</tr>
<tr>
<td class="label">Attachment (optional)</td>
<td><input type="file" name="attachment" /></td>
</tr>
<tr>
<td colspan="2">Comment *<br />
<textarea name="comment_body" rows="10" cols="30"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
HANDLE_FORM.PHP
------------------
<?php
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["sender_name"]) || empty($_POST["sender_email"])
|| empty($_POST["comment_title"]) || empty($_POST["comment_body"]))
{
//redirect back to form
header("Location: ./form.php?error=not_enough_info"); //This should really be an absolute URL if you know it
exit();
}
//Copy into global variables
$name = $_POST["sender_name"];
$email = $_POST["sender_email"];
$title = $_POST["comment_title"];
$body = $_POST["comment_body"];
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9_\\.-]+/", $email))
{
header("Location: ./form.php?error=invalid_email");
exit();
}
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: ./form.php?error=upload_failed");
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Everything looks ok, we can start Swift
require_once "../lib/Swift.php";
require_once "../lib/Swift/Connection/SMTP.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
//Create the message to send
$message =& new Swift_Message("New comment: " . $title);
$message->attach(new Swift_Message_Part($body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
//Try sending the email
$sent = $swift->send($message, "andy@jellybeancreative.co.uk", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: ./success.php");
exit();
}
else
{
header("Location: ./form.php?error=sending_failed");
exit();
}