How to use SMTP function in mail by php

Discussion in 'PHP' started by fingerprint scanner, Jul 1, 2010.

  1. #1
    Can any one tell me how i can implement SMTP function in my this code

    <?php
    $your_email ='biometrics@raydox.com';// <<=== update to your email address

    session_start();
    $errors = '';
    $name = '';
    $visitor_email = '';
    $user_message = '';

    if(isset($_POST['submit']))
    {

    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $user_message = $_POST['message'];
    ///------------Do Validations-------------
    if(empty($name)||empty($visitor_email))
    {
    $errors .= "\n Name and Email are required fields. ";
    }
    if(IsInjected($visitor_email))
    {
    $errors .= "\n Bad email value!";
    }
    if(empty($_SESSION['6_letters_code'] ) ||
    strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
    {
    //Note: the captcha code is compared case insensitively.
    //if you want case sensitive match, update the check above to
    // strcmp()
    $errors .= "\n The captcha code does not match!";
    }

    if(empty($errors))
    {
    //send the email
    $to = $your_email;
    $subject="New form submission";
    $from = $your_email;
    $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

    $body = "A user $name submitted the contact form:\n".
    "Name: $name\n".
    "Email: $visitor_email \n".
    "Message: \n ".
    "$user_message\n".
    "IP: $ip\n";

    $headers = "From: $from \r\n";
    $headers .= "Reply-To: $visitor_email \r\n";

    mail($to, $subject, $body,$headers);

    header('Location: http://www.raydox.com/');
    }
    }

    // Function to validate against any email injection attempts
    function IsInjected($str)
    {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str))
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    ?>
     
    fingerprint scanner, Jul 1, 2010 IP
  2. ZeeshanButt

    ZeeshanButt Well-Known Member

    Messages:
    307
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #2
    I also want to know its solution. Will keep an eye on this thread to know about it. thanks for posting.
     
    ZeeshanButt, Jul 1, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Use the PHPMailer class and follow its documentation for smtp usage.
     
    danx10, Jul 2, 2010 IP
  4. fingerprint scanner

    fingerprint scanner Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Actully i am not getting you even i used PHPmailer function but the problem continue can u plz provide me in detail step by step or nay website where i get help on mail through smtp server.
     
    fingerprint scanner, Jul 6, 2010 IP