phpmailer/phpformgen converting from sendmail to smtp

Discussion in 'PHP' started by SteveA, Dec 28, 2007.

  1. #1
    I'm over my head. I'm trying to adapt the processor.php file to use smtp vs. sendmail as my ISP disallows use of sendmail by php scripts. I have a contact form that passes data to processor.php. I keep the error

    Parse error: syntax error, unexpected T_STRING in /home/prepar6/public_html/forms/processor.php on line 39

    I want to post the data from the form into the body of them message and email it using smtp.

    I'm pre-noob on PHP -struggling to get this done from examples and probably hosed something up in earlier lines. Anyone want to have mercy and take a look at this. I can't be the only person with this challenge - would be glad to post finished product once it works.

    Thanks...



    <?php
    require("class.phpmailer.php");


    $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

    session_start();
    if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "localhost";
    $mail->From = "me@mysite.com";
    $mail->FromName = "me";
    $mail->AddAddress("otherme@othersite.com");

    $mail->SMTPAuth = "true";
    $mail->Username = "me@mysite.com";
    $mail->Password = "xxxxxx";
    $mail->Port = "25";

    $mail->Subject = "P2B Contact form results";
    $mail->Body = "Beginning of data
    Name: " . $_POST['field_1'] . "
    Church: " . $_POST['field_2'] . "
    City: " . $_POST['field_3'] . "
    State: " . $_POST['field_4'] . "
    Daytime Phone: " . $_POST['field_5'] . "
    Email : " . $_POST['field_6'] . "
    Regarding: " . $_POST['field_7'] . "
    Body = Comment/Question: " . $_POST['field_8'] . ";

    $mail->WordWrap = 50;

    if(!$mail->Send()){
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
    include("confirm.html");

    }
    else {
    echo "Invalid Captcha String.";
    }

    ?>
     
    SteveA, Dec 28, 2007 IP
  2. coches

    coches Peon

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Body = Comment/Question: " . $_POST['field_8'] . ";

    becomes
    Body = Comment/Question: " . $_POST['field_8'] . "";
    or even better
    Body = Comment/Question: " . $_POST['field_8'] ;
     
    coches, Dec 29, 2007 IP
  3. SteveA

    SteveA Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It was in fact the ending double quote that was hosing me up. I spent hours trying to get this to work. You are too cool - thanks for the quick fix. :D

    As promised, here is the code from processor.php that allows me to use SMTP instead of sendmail in phpformgenerator using phpmailer.

    <?php
    require("class.phpmailer.php");

    $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

    session_start();
    if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "localhost";
    $mail->From = "me@mysite.com";
    $mail->FromName = "me";
    $mail->AddAddress("otherme@othersite.com");
    $mail->SMTPAuth = "true";
    $mail->Username = "me@mysite.com";
    $mail->Password = "xxxxxx";
    $mail->Port = "25";
    $mail->Subject = "P2B Contact form results";
    $mail->Body = "Beginning of data
    Name: " . $_POST['field_1'] . "
    Church: " . $_POST['field_2'] . "
    City: " . $_POST['field_3'] . "
    State: " . $_POST['field_4'] . "
    Daytime Phone: " . $_POST['field_5'] . "
    Email : " . $_POST['field_6'] . "
    Regarding: " . $_POST['field_7'] . "
    Comment/Question: " . $_POST['field_8'] . "";

    $mail->WordWrap = 50;

    if(!$mail->Send()){
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
    include("confirm.html");
    }
    }
    else {
    echo "Invalid Captcha String.";
    }

    ?>
     
    SteveA, Dec 29, 2007 IP