0

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

11
  • If PHP isn't installed, a lot more than just mail() isn't going to work. If you want to use PHP, you need PHP installed on your server. In what way is mail() not working? Are you getting an error?
    – ceejayoz
    Commented Dec 9, 2020 at 16:28
  • Does this answer your question? PHPMailer install without Composer
    – Nico Haase
    Commented Dec 9, 2020 at 16:31
  • @ceejayoz no im not getting an error. I am running it on a web server not localhost, the message sends, i use an if statement to echo a message if it sends, which it does, but i never receive it. I am still stuck
    – DCT A
    Commented Dec 9, 2020 at 16:50
  • @ceejayoz it worked before but it does not all the sudden even without php installed
    – DCT A
    Commented Dec 9, 2020 at 16:54
  • If you're not getting errors and the message sends, the likely explanation is that the emails are being blocked as spam.
    – ceejayoz
    Commented Dec 9, 2020 at 16:57

1 Answer 1

0

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:

  • the files 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);
  • the PHP script (containing the above code) is UTF-8 encoded.
1
  • Ok. I will surely try that.
    – DCT A
    Commented Dec 10, 2020 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.