require_once "Mail.php"; $username = 'user@gmail.com'; $password = 'password'; $smtpHost = 'ssl://smtp.gmail.com'; $smtpPort = '465'; $to = 'mail@to.com'; $from = 'user@gmail.com'; $subject = 'Contact Form'; $successMessage = 'Message successfully sent!'; $replyTo = ''; $name = ''; $body = ''; $headers = array( 'From' => $name . " <" . $from . ">", 'To' => $to, 'Subject' => $subject ); $smtp = Mail::factory('smtp', array( 'host' => $smtpHost, 'port' => $smtpPort, 'auth' => true, 'username' => $username, 'password' => $password )); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo($mail->getMessage()); } else { echo($successMessage); }