www139 www139 - 2 months ago 37
PHP Question

php mailer not working on 000webhost

This code seems to work in xampp on my mac localhost but it doesn't seem to work on my free 000webhost account. I already tried getting rid of ssl but it didn't help. Keep in mind that this program get variables from an external form. Thanks :D

<?php
$subject = htmlentities($_POST['subject']);
$email = $_POST['email'];
$message = htmlentities($_POST['message']);




require_once 'PHPMailer/PHPMailerAutoload.php';

$m = new PHPMailer;

$m->isSMTP();
$m->SMTPAuth = true;
//$m->SMTPDebug = 1;
$m->Host = 'smtp.gmail.com';
$m->Username = 'email-adress@gmail.com';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;

$m->From = 'email-adress@gmail.com';
$m->FromName = 'William Green';
$m->addReplyTo('email-adress@gmail.com', 'William Green');

//$m->addCC('email2-address@gmail.com', 'Willliam green');


########################################
//email code
//$recipient = strip_tags($_POST['mailRecipient']);
//$name = strip_tags($_POST['recipientsName']);


$m->addAddress($email, $email);



//$m->Subject = strip_tags($_POST['mailSubject']);
//$m->Body = strip_tags($_POST['mailBody']);
$m->Subject = $subject;
$m->Body = $message;


//$m->AltBody = 'plain text version!';


###########################################





//var_dump($m->send());
if ($m->send())
{
echo '<h1 class="good">Email Sent!</h1>';
}
else
{
echo '<h1 class="bad">Email Not Sent!</h1>';
}


?>

Answer

"but it doesn't seem to work on my free 000webhost account"

A: They do not offer SMTP for free hosting. Use PHP's mail() function instead.

Notice the red x next to SMTP Server on their site => http://www.000webhost.com/ ?

enter image description here

Either use mail() or pay for it in order to use SMTP.

You can do it on their website, or upgrade from within the control panel.

Edit (Sept. 16, 2016): This answer was posted before they revamped their website. The URL where you can see the available options for free/paid services, can be see here https://www.000webhost.com/premium-web-hosting

This also goes for remote connections to a database.

This answer was edited in regards to a question I saw today which was related to my edit.

Comments