Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Send email using the GMail SMTP server from a PHP page

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 136
    Comment on it

    Hello Readers!

    You people can use below code if you are using Gmail SMTP connection.

    $from = '<fromaddres@gmail.com>';
    $to = '<toaddress@yahoo.com>';
    $subject = 'Hi!';
    $body = "Hi, How are you?";
    
    $headers = array(
        'From' => $from,
        'To' => $to,
        'Subject' => $subject
    );
    
    $smtp = Mail::factory('smtp', array(
            'host' => 'ssl://smtp.gmail.com',
            'port' => '465',
            'auth' => true,
            'username' => 'username@gmail.com',
            'password' => 'passwordxxx'
        ));
    
    $mail = $smtp->send($to, $headers, $body);
    
    if (PEAR::isError($mail)) {
        echo('<p>' . $mail->getMessage() . '</p>');
    } else {
        echo('<p>Message successfully sent!</p>');
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: