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?
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.
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.
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.
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.
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; } ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With