I want to know how do I get a SMTP server to use PHPMailer
to send automatic emails with my created email (email@mydomain.com).
My webhost doesn't provide one. I brought my domain in OnlyDomains
and my webhost is 000Webhost
.
<?php
require './PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ''; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noreply@mydomain.com'; // SMTP username
$mail->Password = '********'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->From = 'noreply@mydomain.com';
$mail->FromName = 'Admin';
$mail->addAddress('sdfsdf@hotmail.com'); // Name is optional
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'swag';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
You should see if your web host allows you to use
sendmail
on their system. STMP is not needed withsendmail
. Chances are they do since it is a standard part of most any Linux/Unix setup. And since you say that your web host is000WebHost
it seems like they do support the use ofsendmail
:But they also seem to offer SMTP in their premium package.
Past that, I would recommend not worrying about SMTP & sticking to
sendmail
for now. Looking at the documentation forPHPMailer
it seems that the library can usesendmail
:Then looking in the
examples/
folder in thePHPMailer
repository shows there is asendmail
example: