Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    Feb 2011
    Location
    Montana
    Posts
    3

    Default PHPMailer help request

    I created a mail form using PHPMailer that once the user enters his / her information and selects 'submit', the page redirects to a thank you page.
    It works as advertised on localhost, but when I upload to the Westhost server the submit button takes you to a echo printout indicating mail has been delivered:

    After Submit it selected, this is what appears in the browser:
    SMTP -> FROM SERVER:xxxxxx ESMTP Exim 4.69 #1 Sat, 19 Feb 2011 06:33:07 -0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
    SMTP -> FROM SERVER: xxxxxxxx [xxx.xxx.xx.xxx] 250-SIZE 52428800 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
    SMTP -> FROM SERVER:250 OK
    SMTP -> FROM SERVER:250 Accepted
    SMTP -> FROM SERVER:354 Enter message, ending with "." on a line by itself
    SMTP -> FROM SERVER:250 OK id=1Pqmvr-0000Fj-U7
    Message Sent OK

    Here is the code I use to send the email:

    <?php

    require_once('../phpmailer/class.phpmailer.php');
    //include("../class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

    $mail->IsSMTP(); // telling the class to use SMTP

    try {
    $mail->Host = "xx.xxxxxx.com"; // SMTP server
    $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->Host = "xxxxxxxx[syntax=php][/syntax]"; // sets the SMTP server
    $mail->Port = xx; // set the SMTP port for the GMAIL server
    $mail->Username = "xxxxxxxxxxx"; // SMTP account username
    $mail->Password = "xxxxxxxxxx"; // SMTP account password
    $mail->AddReplyTo($_POST["email"], $_POST["first_name"]." ".$_POST["last_name"]);
    $mail->AddAddress('xxxx@gxxxxx.net', 'Robert Good');
    //$mail->AddAddress('xxxxx@ixxxx.net', 'Charity Waldo');
    $mail->SetFrom('mail@xxxxx.com', 'Web Site Contact');
    $mail->Subject = 'Contact Message from cbmasonco.com';
    //$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
    $mail->Body = "First Name: ".$_POST["first_name"]."\nLast Name: ".$_POST["last_name"]."\nTelephone: ".$_POST["telephone"]."\nEmail: ".$_POST["email"]."\n"."\nComments/Questions: "."\n".$_POST["comments"];
    //$mail->AddAttachment('images/phpmailer.gif'); // attachment
    //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
    $mail->Send();
    echo "Message Sent OK</p>\n";
    } catch (phpmailerException $e) {
    echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
    echo $e->getMessage(); //Boring error messages from anything else!
    }

    header('Location: http://www.timbercreekgraphics.com/success.php');
    ?>


    Any tips would be greatly appreciated. I am at a dead end on this one.
    If not totally obvious, I am not a PHP developer!!!

  2. #2
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    Not sure why you did not also get the output on your localhost since it is doing exactly what you told it to do. It has been some time since I used phpmailer class but pretty sure the reason you are getting the SMTP -> FROM SERVER output is because of this line of code:
    PHP Code:
    $mail->SMTPDebug 2// enables SMTP debug information (for testing) 
    If I recall the class correctly it echos the debug information as it goes along. You also have this bit of code:
    PHP Code:
    echo "Message Sent OK</p>\n"
    In PHP once you echo or print something you have in essence already sent the header information to the browser so you can no longer use the header function to redirect to a web page.

    Give this a try:
    PHP Code:
    <?php

    require_once('../phpmailer/class.phpmailer.php');
    //include("../class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

    $mail->IsSMTP(); // telling the class to use SMTP

    try {
    $mail->Host "xx.xxxxxx.com"// SMTP server
    //$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
    $mail->SMTPAuth true// enable SMTP authentication
    $mail->Host "xxxxxxxx[syntax=php][/syntax]"// sets the SMTP server
    $mail->Port xx// set the SMTP port for the GMAIL server
    $mail->Username "xxxxxxxxxxx"// SMTP account username
    $mail->Password "xxxxxxxxxx"// SMTP account password
    $mail->AddReplyTo($_POST["email"], $_POST["first_name"]." ".$_POST["last_name"]);
    $mail->AddAddress('xxxx@gxxxxx.net''Robert Good');
    //$mail->AddAddress('xxxxx@ixxxx.net', 'Charity Waldo');
    $mail->SetFrom('mail@xxxxx.com''Web Site Contact');
    $mail->Subject 'Contact Message from cbmasonco.com';
    //$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
    $mail->Body "First Name: ".$_POST["first_name"]."\nLast Name: ".$_POST["last_name"]."\nTelephone: ".$_POST["telephone"]."\nEmail: ".$_POST["email"]."\n"."\nComments/Questions: "."\n".$_POST["comments"];
    //$mail->AddAttachment('images/phpmailer.gif'); // attachment
    //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
    $mail->Send();
    header('Location: http://www.timbercreekgraphics.com/success.php');
    } catch (
    phpmailerException $e) {
    echo 
    $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
    echo 
    $e->getMessage(); //Boring error messages from anything else!
    }
    ?>
    In the above I simply commented out the setting of $mail->SMTPDebug. Like I say I can't remember the class for sure so double check the documentation and see if you need to actually turn off the debugging. Normally things like this have debugging turned off by default unless you set it.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  3. #3
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    P.S. Do you really want to use the form input from the user without any filtering? That would be everyplace where you have $_POST['a form input variable']. That just opens you up to hackers. Maybe you want to use a pre-made program already out there. If you are on a cPanel account then there are quite a few you can install via Softacoules. If you are on a Site Manager account then you have the option of FormMail via the Install area.

    Just thought I should point that out. Could be you where planning to filter the content once you had the basics worked out. I know I do that sometimes.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Location
    Montana
    Posts
    3

    Default

    thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you....

    I cannot say it enough.

    I do have a filter setup with this function on the page itself:
    function isEMailAddress(val){
    if (val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/)){
    return true;
    }else{
    return false;
    }

    I will look into what Softacoules has to offer through cpanel

    Thank you wildjokerdesign!

  5. #5
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    You still want to filter your other input. Here is just one example of a class you can use: http://www.phpclasses.org/package/21...TML-tags-.html You can also use the builtin PHP filters: http://us2.php.net/manual/en/book.filter.php and http://www.w3schools.com/PHP/php_filter.asp
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  6. #6
    Junior Member
    Join Date
    Feb 2011
    Location
    Montana
    Posts
    3

    Default

    Great, I will read up on filtering and Sanitizing.

    Thanks again!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •