Akai shur
Akai shur

Reputation: 187

PHPMailer not working in web page

I'm trying to send an email with PHPMailer, but it's not working for me so far.

On my FTP I've put 2 files, the class.phpmailer.php and sendEMail.php (this file is created by me), with this content:

<?php
require_once('/var/www/vhosts/MYWEBPAGE/httpdocs/class.phpmailer.php');

$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "mail.dom.com"; 
$mail->Username = "[email protected]"; 
$mail->Password = "passwd"; 
$mail->Port = 25; 

$mail->setFrom("[email protected]", "me", 0);

$mail->addAddress("[email protected]"); 

$mail->Subject = "test"; 
$body = "Hello World!";
$mail->Body = $body; 

if(!$mail->send()) {
echo ("Invoice could not be send. Mailer Error: " . $mail->ErrorInfo);
} else {
echo "Invoice sent!";
}

?>

I'm missing something? When I execute this file, it shows me nothing, i mean before the if(!$mail->send()) {... It shows me every echo, but after that line, it shows me nothing.

Upvotes: 0

Views: 1428

Answers (1)

Synchro
Synchro

Reputation: 37810

It's because you've not read the readme that tells you what files you need, nor based your code on the examples provided. You've not loaded the SMTP class, nor the autoloader that will load it for you, so as soon as you try to send, it will fail to find the SMTP class. This will be logged in your web server logs like any other PHP fatal error.

Instead of this:

require_once('/var/www/vhosts/MYWEBPAGE/httpdocs/class.phpmailer.php');

do this:

require '/var/www/vhosts/MYWEBPAGE/httpdocs/PHPMailerAutoload.php';

Upvotes: 1

Related Questions