Question:
How do I convert php mail script for smtp for website?
Reave
2010-09-04 06:16:23 UTC
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 ///////////////////////////////////////////

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 = "james@example.com";
$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 = "yourusername@gmail.com"; // SMTP username
$mail->Password = "yourpassword"; // SMTP password

$mail->From = "email address sender";
Three answers:
Gitlez
2010-09-04 23:33:20 UTC
Here you go... Look into scrubbing the user input before using it in your script. Just as a safety precaution.





Cheers,

Gitlez



Follow up questions --> gitlez[ANTi-SPAM]@gmx.com

Remove the [ANTi-SPAM] bit.










if(!$_POST) exit;



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



// ===== New Mail Function =====

function smtpMail($to, $from_name, $from_email, $subject, $body){



$mail = new PHPMailer();

$mail->IsSMTP();

$mail->SMTPAuth = true;

$mail->SMTPSecure = 'ssl';

$mail->Host = 'smtp.gmail.com';

$mail->Port = 465;

$mail->Username ="YOUR_USERNAME";

$mail->Password = "YOUR_PASSWORD";

$mail->SetFrom($from_email, $from_name);

$mail->Subject = $subject;

$mail->Body = $body;

$mail->AddAddress($to);



return $mail->Send();

}



// ===== ===== ===== ===== =====

$email = $_POST['email'];





//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+… $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';

if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+… ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\… )){

$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 = "james@example.com";

$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(@smtpMail($your_email, $receipient_email, $receipient_name, $email_subject, $email_content) {

echo 'Message sent!';

} else {

echo 'ERROR! Message was NOT sent.';

}

}



?>
?
2016-04-13 02:17:23 UTC
First of all u have to educate those hindus who are being converted. Next u should know why those hindus are accepting conversion and the problems they are facing. U should make them understand that after conversion Christian Missionaries will leave them to dogs. Bring this matter to the notice of Ramsena activists. U can bring this matter to the Police too and get their help if they are really willing to help.
2014-03-15 09:45:58 UTC
Hello,



Take a look at this site, may be it can help you

http://webhostingsecretsonline.com



Best of Luck


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...