SMTP insteaf of localhost in PHP form

Discussion in 'Email' started by dinney, Sep 15, 2011.

  1. Hi,

    I have this form in a flash website, with the php as follows. I am told i need to use SMTP authentication instead of calling the localhost in order for the form to work. Can someone please tell me what i need to modify in order to use SMTP authentication here??

    <?php

    $name = $HTTP_POST_VARS['name'];
    $position = $HTTP_POST_VARS['position'];
    $school = $HTTP_POST_VARS['school'];
    $city = $HTTP_POST_VARS['city'];
    $state = $HTTP_POST_VARS['state'];
    $email = $HTTP_POST_VARS['email'];
    $phone = $HTTP_POST_VARS['phone'];
    $cellphone = $HTTP_POST_VARS['cellphone'];
    $comment = $HTTP_POST_VARS['comment'];

    $name = stripslashes($name);
    $position = stripslashes($position);
    $school = stripslashes($school);
    $city = stripslashes($city);
    $state = stripslashes($state);
    $email = stripslashes($email);
    $phone = stripslashes($phone);
    $cellphone = stripslashes($cellphone);
    $comment = stripslashes($comment);

    $rec_email = "[email protected]"; // do kogo email
    $subject = "Contact form"; // temat emaila

    //zbieranie i wyswietlanie danych
    $msg_body = "------------------------------------------\n";
    $msg_body .= "Name: $name\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Your Position with the School or Facility: $position\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Name of School or Facility: $school\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "City (School - Facility): $city\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "State (School - Facility): $state\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Email: $email\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Daytime Phone: $phone\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Cell Phone: $cellphone\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "\n";
    $msg_body .= "Question or Comment: $comment\n";
    $msg_body .= "\n\n";

    //$header_info = "Od: ".$name." <".$email.">";
    $header_info = "FROM: $name <$email>\r\n";
    mail($rec_email, $subject, $msg_body, $header_info);

    echo "&errormsg=message has been sent&";
    ?>


    --------------------------------------------

    I was told i need to add this --
    <html>
    <head><title>Test email via php</title></head>
    <body>
    <?
    require_once "Mail.php";
    $from = "Sender <[email protected]>";
    $to = "Recipient <[email protected]>";
    $subject = "This is a test email sent via php";
    $body = "This is a test email";
    $host = "mail.HostingAccountDomain.com";
    $username = "[email protected]";
    $password = "email_password";
    $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));
    $mail = $smtp->send($to, $headers, $body);
    ?>
    </body>
    </html>
     
  2. Yes, that should have been pulled from our knowledge base article.

    However do you mind providing me with a domain name so that I could look into the issue a little further?

    Are you getting any error messages and is there a test link?
     
    Last edited by a moderator: Oct 14, 2015
  3. Yes,

    The website is

    www.nationalcircusproject.com

    The test form is here:

    http://www.nationalcircusproject.com/test/ (click on the contact us section)

    There is no error message it just says sending but never sends. since ive been told not to use localhost, i dont know how to use SMTP instead???

    Here is the script:
    <?php

    $name = $HTTP_POST_VARS['name'];
    $position = $HTTP_POST_VARS['position'];
    $school = $HTTP_POST_VARS['school'];
    $city = $HTTP_POST_VARS['city'];
    $state = $HTTP_POST_VARS['state'];
    $email = $HTTP_POST_VARS['email'];
    $phone = $HTTP_POST_VARS['phone'];
    $cellphone = $HTTP_POST_VARS['cellphone'];
    $comment = $HTTP_POST_VARS['comment'];



    $name = stripslashes($name);
    $position = stripslashes($position);
    $school = stripslashes($school);
    $city = stripslashes($city);
    $state = stripslashes($state);
    $email = stripslashes($email);
    $phone = stripslashes($phone);
    $cellphone = stripslashes($cellphone);
    $comment = stripslashes($comment);

    $rec_email = "[email protected]"; // do kogo email
    $subject = "Contact form"; // temat emaila

    //zbieranie i wyswietlanie danych
    $msg_body = "------------------------------------------\n";
    $msg_body .= "Name: $name\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Your Position with the School or Facility: $position\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Name of School or Facility: $school\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "City (School - Facility): $city\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "State (School - Facility): $state\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Email: $email\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Daytime Phone: $phone\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "Cell Phone: $cellphone\n";
    $msg_body .= "-----------------------------------------\n";
    $msg_body .= "\n";
    $msg_body .= "Question or Comment: $comment\n";
    $msg_body .= "\n\n";



    //$header_info = "Od: ".$name." <".$email.">";
    $header_info = "FROM: $name <$email>\r\n";
    mail($rec_email, $subject, $msg_body, $header_info);

    echo "&errormsg=message has been sent&";
    ?>
     
  4. deepak11627

    deepak11627 Guest

    Hi,
    Problem sending email from you localhost, use gmail smtp to do this. here is a php code to do it.
    function gmailSmtp($from,$to,$subject,$body,$bcc = false){
    require_once "Mail.php";
    $body = stripslashes(stripslashes($body));
    $host = "ssl://smtp.gmail.com";
    $port = "465";
    $username = "[email protected]";
    $password = "Google123#";
    if($bcc){
    $headers = array (
    'MIME-Version'=> '1.0',
    'Content-type' => 'text/html; charset=iso-8859-1',
    'From' => $from,
    'RCPT TO' => $to,
    'Subject' => $subject
    );
    }else{
    $headers = array (
    'MIME-Version'=> '1.0',
    'Content-type' => 'text/html; charset=iso-8859-1',
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
    );
    }
    //print_r($headers);die;
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));
    $mail = $smtp->send($to, $headers, $body);
    if (PEAR::isError($mail)) {
    return $mail->getMessage();
    } else {
    return 1;
    }
    }
    Here you sure that mail.php file in there in the library folder.
    Thanks
    CoreIT Developers!
     

Share This Page