user198729
user198729

Reputation: 63636

How to send email without my own mail server by PHP?

Is it possible to use Google's mail server for testing purpose,and replace the address of mail server when my own server is ready?

Upvotes: 2

Views: 7985

Answers (4)

Strae
Strae

Reputation: 19445

I suggest you to use phpmailer, this is an example working code with it:

<?php
include_once("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the server
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = 'smtp.gmail.com';
// set the SMTP port
$mail->Port = '465';
// GMAIL username
$mail->Username = '[email protected]';
// GMAIL password
$mail->Password = 'your-gmail-password';

$mail->From = 'email address who send the email';
$mail->FromName = 'yourname';
$mail->AddReplyTo('email to reply', 'name to reply');
$mail->Subject = 'Test Gmail!';
if($is_your_mail_an_html){
    $mail->MsgHTML($html_message);
    $mail->IsHTML(true);
}else{
    $mail->Body = $text_message;
    $mail->IsHTML(false);

}
$mail->AddAddress('to address email', 'to name');

if(!$mail->Send()){
    echo = $mail->ErrorInfo;
}else{
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
?>

But even without phpmailer, you can use gmail to send emails; Just set the port to 465 and enable the ssl auth.

P.s.: dont try to send nesletter throught gmail; they will block your account for 1 day if you send more than $x email per day ($x is 500 on the google documentation, but my experience say that is around 85!)

Upvotes: 1

Christoffer
Christoffer

Reputation: 26825

If you run a Windows server you can just do this (if you have access to the php.ini). Otherwise follow Sarfraz suggestion.

<?php
ini_set('sendmail_from','[email protected]');
ini_set('SMTP','smtp.test.net');

mail(...);
?>

Upvotes: 0

Konamiman
Konamiman

Reputation: 50273

You can just send your mails via smtp.gmail.com (port 465 or 587) as with any email client. Note anyway that you will need a Google email account for this. More details are here: Configuring email clients for using GMail

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382696

Yes google does offer that via smtp.

smtp.google.com

port: 587

You also will need your google username and password to send emails.

You need a php smtp class. PHPMailer has one.

Upvotes: 0

Related Questions