I need to send emails and the mail()
function just does not work for me.
The problem is that PHP is not installed on my device. Can I still use it in, index.php
for example?
I use 000webhost
Try this code (it works for me):
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'PHPMailer.php';
require 'SMTP.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'xxx'; // Change here
$mail->Password = 'xxx'; // Change here
$mail->setFrom('xxx', 'Mailer'); // Change here
$mail->addAddress('xxx'); // Change here
$mail->isHTML();
$mail->CharSet = 'utf-8';
$mail->Subject = 'Subject';
$mail->Body = 'Hello world';
echo $mail->Send() ? 'OK!' : 'Something went wrong';
Be sure that:
PHPMailer.php
and SMTP.php
are in the same folder of the PHP script (I suggest you to put them all in the root of your website, for now);
mail()
isn't going to work. If you want to use PHP, you need PHP installed on your server. In what way ismail()
not working? Are you getting an error?