Riclea Andrei
Riclea Andrei

Reputation: 79

php mailer in function generates error

I created a function to handle email sending using PHPMailer

this is the function:

function sendEmail($from, $replyTo, $to, $subject, $message) {
$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mail.pickbyclick.ro';  // Specify main and backup SMTP servers
$mail->SMTPAuth = false;
$mail->Username = '[email protected]';
$mail->Port = 25; 

$mail->setFrom($from, 'Pick by Click Team');
$mail->addReplyTo($replyTo);
$mail->addAdress($to);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = emailShowNice($message);
$mail->AltBody = $message;
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

}

And after this call

sendEmail($from, "[email protected]", $to, $subject, $message);

It shows 500 error server. Can anyone please help me?

Edit: this is the emailShowNice function

function emailShowNice($message) {

$order   = array('\r', '\n', '\r\n', "\r", "\n", "\r\n");
$replace = ' <br /> ';

$mes = str_replace($order, $replace, $message);

return $mes;
}

Upvotes: 0

Views: 42

Answers (1)

Muhammad Usman
Muhammad Usman

Reputation: 1423

Replace the line a mistake here

$mail->addAdress($to);

with

$mail->addAddress($to);

Upvotes: 1

Related Questions