moving host causes errors

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

roscoe
Forum Commoner
Posts: 85
Joined: Tue Aug 05, 2003 10:24 am
Location: essex uk

Post by roscoe »

I am confused, perhaps suicide would be better :?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

This is purely for debug... do not keep the script this way, but what does this say?

Code: Select all

//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"]; 
$sendout = $_POST["to"]; 
//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 "mylib/Swift.php"; 
require_once "mylib/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"); 
} 


$smtp =& new Swift_Connection_SMTP("localhost"); 
//Create a Swift instance 
//$swift =& new Swift(new Swift_Connection_SMTP("your_smtp_server.tld")); 
//Try to connect using /usr/sbin/sendmail -bs 
//$sendmail =& new Swift_Connection_Sendmail(); 
//$sendmail->setTimeout(3); //3 seconds 

$swift =& new Swift($smtp); 
$swift->log->enable();

//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, $sendout, $sender); 
//Disconnect from SMTP, we're done 
$swift->disconnect(); 

if ($sent) 
{ 
    header("Location: success.php"); 
    exit(); 
} 
else 
{     echo"sending_failed";
       $swift->log->dump();
        exit; 
    header("Location: form.php?error=sending_failed"); 
    exit(); 
}
roscoe
Forum Commoner
Posts: 85
Joined: Tue Aug 05, 2003 10:24 am
Location: essex uk

Post by roscoe »

you truly are the master, The debug told me that cos The domain has not moved but the box exists the email was not dispatched.

I now have to see if the host can ensure that it follows the mx record :lol:
Post Reply