Welcome to Sign in | Join | Help
Home Forums Photos Downloads

contact form issue

  •  11-30-2006, 11:23 PM

    contact form issue

    Hello,

    I am migrating a contact form that was working on another host site.  It uses SMTP authentication but is currently giving an error on submit that echo's part of the code- including sending email and password!  The code is echoed back to the screen starting with this line   

        echo "\n<br>That is not a valid email address.  Please <a href=\"BLOCKED SCRIPThistory.back()\">return</a> to the previous page and try again.\n<br>";

    Any help would be greatly appreciated.  This site also has an ASP.Net contact form using same credentials for SMTP and that works just fine.   

    Following is the code:

    <?
    require("class.phpmailer.php"); //require the class code

    $name     = $_POST['name'];
    $address  = $_POST['address'];
    $state    = $_POST['state'];
    $city     = $_POST['city'];
    $zip      = $_POST['zip'];
    $country  = $_POST['country'];
    $phone    = $_POST['phone'];
    $email    = $_POST['email'];
    $comments = $_POST['comments'];
    $fax      = $_POST['fax'];
    $error_msg = "";
    $msg = "";

    if(!$name){
        $error_msg .= "Your name \n";
    }
    if($name){
        $msg .= "Name: \t $name \n";
    }
    if (!$state) {
        $error_msg .= "Your state \n";
    }
    if ($state) {
        $msg .="State: \t $state \n";
    }
    if(!$email){
        $error_msg .= "Your email \n";
    }
    if($email){
        if(!eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\._\-]+\.[a-zA-Z]{2,4}", $email)){
            echo "\n<br>That is not a valid email address.  Please <a href=\"BLOCKED SCRIPThistory.back()\">return</a> to the previous page and try again.\n<br>";
            exit;
        }           
        $msg .= "Email: \t $email \n";
    }

    if($comments){
        $msg .= "Comments: \t $comments \n";
    }
    $sender_email="";

    if(!isset($name)){
        if($name == ""){
            $sender_name="Web Customer";
        }
    }else{
        $sender_name=$name;
    }
    if(!isset($email)){
        if($email == ""){
            $sender_email="Customer@website.com";
        }
    }else{
        $sender_email=$email;
    }
    if($error_msg != ""){
        echo "You didn't fill in these required fields:<br>"
        .nl2br($error_msg) .'<br>Please <a href="BLOCKED SCRIPThistory.back()">return</a> to the previous page and try again.';
        exit;
    }

    $mail = new PHPMailer(); // create an instance of the mailer class

    $mail->IsSMTP();                                      // set mailer to use SMTP
    $mail->Host = "mail.domainname.com";  // specify server
    $mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username = "webmailer@domainname.com";  // SMTP username
    $mail->Password = "password"; // SMTP password

    $mail->From = "webmailer@domainname.com";
    $mail->FromName = "webmailer@domainname.com";
    $mail->AddAddress("brian@domainname.com", "Brian");
    $mail->AddReplyTo($sender_email, $sender_name);

    $mail->WordWrap = 50;                                 // set word wrap to 50 characters
    $mail->IsHTML(true);                                  // set email format to HTML

    $mail->Subject = " WEB REQUEST";
    $mail->Body    =stripslashes($msg);
    $mail->AltBody =stripslashes($msg);
    if(!$mail->Send())
    {
       echo "Message could not be sent. <p>";
       echo "Mailer Error: " . $mail->ErrorInfo;
       exit;
    }
    header("Location: http://domainname.com/thankyou.html");
     ?> 

    Filed under:
View Complete Thread
Powered by Community Server, by Telligent Systems