mardi 28 juin 2016

using phpmailer in contact form in wordpress, works in localhost but not server

I've been working on a contact email form on my own localhost in wordpress before I move it onto the actual website. This is how i've been sending the mail on my localhost:

require_once(ABSPATH . WPINC . '/class-phpmailer.php');
$pmail = new PHPMailer();
$pmail->From = strip_tags($email);
$pmail->FromName = $fullname;
$pmail->Subject = $subject;
$pmail->IsHTML(true);
$pmail->AddAddress('example@gmail.com', 'Simon');
$pmail->AddAttachment($filepath,$filename);
$pmail->Body = $message;
if($pmail->Send()) my_contact_form_generate_response("success", $message_sent);
else my_contact_form_generate_response("error", $message_unsent);
echo $pmail->Errorinfo;

I've tried adding this SMTP code but im not sure if I did it correctly or if thats how you do it.

Adding this:

$pmail->Host     = "smtp.gmail.com"; // SMTP server
$pmail->Port = 465;
$pmail->SMTPAuth = true;
$pmail->Username = "my@gmail.com";
$pmail->Password = "mypass";
$pmail->isSMTP();
$pmail->SMTPSecure = 'ssl';

The error message i've been getting is "Could not instantiate mail function".

When I added the SMTP my error was "SMTP connect() failed."



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire