Как отправить контактную форму в WordPress с помощью phpmailer и куда ее перенаправить - PullRequest
0 голосов
/ 06 января 2020

куда поместить этот код конфигурации

session_start();

require 'phpmailer/class.phpmailer.php';

require 'phpmailer/class.smtp.php';
$result="";
if(isset($_POST['submit'])){


$to = "username"; 
$from = "username"; 
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$company = $_POST['company'];

$subject = $_POST['subject'];
$message = $_POST['msg'];

$msg = 'Full Name : '. $name . " " .  "\n\n<br>" . 'Corporate Email : ' . $_POST['email']."\n\n<br>" 
. 'Mobile : ' . $_POST['mobile']."\n\n<br>" . 'Company : ' . $_POST['company']   . "\n\n<br>" . 
'Subject 
: ' . $_POST['subject'] . "\n\n<br>" . 'Message : ' . $_POST['msg'];


$mail = new PHPMailer(true);          // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 1;                     // Enable verbose debug output
$mail->isSMTP();                             // Set mailer to use SMTP
$mail->Host = 'smtp.rediffmailpro.com';   // Specify main and backup SMTP servers
$mail->SMTPAuth = true;           // Enable SMTP authentication
$mail->Username = 'username';          // SMTP username
$mail->Password = 'pass';                          // SMTP password
$mail->SMTPSecure = 'ssl';            // Enable TLS encryption`ssl` also accepted
$mail->Port = 465;                           // TCP port to connect to

//Recipients
$mail->setFrom($email, $name);
$mail->addAddress('username', 'Seema User');     // Add a recipient
          // Name is optional
$mail->addReplyTo('username', 'Seema');

//Content
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = $_post['subject'];
$mail->Body    = $msg;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send())
{
$result="Something went wrong......";
}
else{
    $result="Your inquiry has been submitted, our team will get in touch with you shortly.";
}


} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

Обычно мы включаем его в тот же файл или можем создать другой файл для управления им, но WordPress имеет свои собственные правила для управления им. Может кто-нибудь объяснить, как использовать код phpmailer в WordPress шаг за шагом. Буду признателен вам, если вы мне поможете.

...