How do I convert php mail script for smtp for website?

  • Thread starter Thread starter Reave
  • Start date Start date
R

Reave

Guest
I currently am using xtreemhost for webhosting but they don't support php default mail(). So I want to use smtp instead. I just need help implementing/convert the smtp code into my current php script so it will work with smtp. I found a tutorial at (http://xtreemhost.com/2010/04/11/how-to-send-e-mails-via-smtp-with-phpmailer-and-gmail/) but it doesn't really help except to set it up. Below is my current contact.php


/////////////////////////////////////////// contact.php ///////////////////////////////////////////
<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','message');
$required = array('name','email','message');

$your_email = "[email protected]";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";

foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}

if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR! Message was NOT sent.';
}
}
?>


/////////////////////////// Need to add this to contact.php if possible ///////////////////////////////

require("class.phpmailer.php"); // path to the PHPMailer class

$mail = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "yourpassword"; // SMTP password

$mail->From = "email address sender";
 
Back
Top