PHP Mailer - contact form issue

喜欢而已 提交于 2019-12-11 15:14:23

问题


I would like to write Simple Contact Form. I use code as below

<?php

// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

// When we unzipped PHPMailer, it unzipped to
// public_html/PHPMailer_5.2.0
require('C:\xampp\php\lib\PHPMailer\PHPMailerAutoload.php');

$mail = new PHPMailer();

// set mailer to use SMTP
$mail->IsSMTP();

// As this email.php script lives on the same server as our email server
// we are setting the HOST to localhost
$mail->Host = "smtp.wp.pl";  // specify main and backup server

$mail->SMTPAuth = true;     // turn on SMTP authentication

// When sending email using PHPMailer, you need to send from a valid email address
// In this case, we setup a test email account with the following credentials:
// email: send_from_PHPMailer@bradm.inmotiontesting.com
// pass: password
$mail->Username = "test@wp.pl";  // SMTP username
$mail->Password = "test"; // SMTP password

// $email is the user's email address the specified
// on our contact us page. We set this variable at
// the top of this page with:
// $email = $_REQUEST['email'] ;
$mail->From = $email;

// below we want to set the email address we will be sending our email to.
$mail->AddAddress("test@wp.pl", "Test na WP");

// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);

$mail->Subject = "You have received feedback from your website!";

// $message is the user's message they typed in
// on our contact us page. We set this variable at
// the top of this page with:
// $message = $_REQUEST['message'] ;
$mail->Body    = $message;
$mail->AltBody = $message;

if(!$mail->Send())
{
   echo "Message could not be sent.
";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>

But I get errror:

Fatal error: Uncaught Error: Class 'PHPMailer' not found in C:\xampp\htdocs\contact.php:12 Stack trace: #0 {main} thrown in C:\xampp\htdocs\contact.php on line 12

Please, tell what I should change in this code. I tried add PHPMailer.php class in C:\xampp\htdocs and C:\xampp\php\lib but it's didn't help me. Should I add this file in other location ? Or add other PHPMailer class files?

来源:https://stackoverflow.com/questions/51859468/php-mailer-contact-form-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!