Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send email from PHP without SMTP server installed?

Tags:

I have a classic LAMP platform (Debian, Apache2, PHP5 and MySQL) on a dedicated server.

I heard PHPMailer can send email without having installed SMTP. Is PHPMailer the best choice for this?

like image 790
dynamic Avatar asked Feb 10 '11 22:02

dynamic


People also ask

Can we send email without SMTP server?

Without an SMTP server, you cannot send your email to its destination. When you click the “send” button from your email client, your email messages get automatically converted into a string of codes and are transferred to your SMTP server.

Does PHP mail require SMTP?

PHP mail() does not usually allow you to use the external SMTP server and it does not support SMTP authentication. Here's what you can do with PHP's built-in mail function(): create simple HTML/text messages without attachments and images.

Can we send mail from localhost in PHP?

You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP. So if you are using XAMPP then you can easily send mail from localhost. For example, you can configure C:\xampp\php\php.

Can you send email from PHP?

1. Using the PHP mail() function. PHP's built-in mail() function is one of the simplest ways to send emails directly from the web server itself. It just takes three mandatory parameters: the email address, email subject and message body—and sends it to the recipient.


1 Answers

Yes, PHPMailer is a very good choice.

For example, if you want, you can use the googles free SMTP server (it's like sending from your gmail account.), or you can just skip the smtp part and send it as a typical mail() call, but with all the correct headers etc. It offers multipart e-mails, attachments.

Pretty easy to setup too.

<?php  $mail = new PHPMailer(true);  //Send mail using gmail if($send_using_gmail){     $mail->IsSMTP(); // telling the class to use SMTP     $mail->SMTPAuth = true; // enable SMTP authentication     $mail->SMTPSecure = "ssl"; // sets the prefix to the servier     $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server     $mail->Port = 465; // set the SMTP port for the GMAIL server     $mail->Username = "[email protected]"; // GMAIL username     $mail->Password = "your-gmail-password"; // GMAIL password }  //Typical mail data $mail->AddAddress($email, $name); $mail->SetFrom($email_from, $name_from); $mail->Subject = "My Subject"; $mail->Body = "Mail contents";  try{     $mail->Send();     echo "Success!"; } catch(Exception $e){     //Something went bad     echo "Fail - " . $mail->ErrorInfo; }  ?> 
like image 167
Mārtiņš Briedis Avatar answered Sep 20 '22 18:09

Mārtiņš Briedis