Answer the question
In order to leave comments, you need to log in
Why POST requests don't work when sent via PHP mailer?
Good evening, I connected PHPMailer to my site, after which I thought to add add requests in this way, but a letter arrives in the mail in the form:
Application from $name $eemail
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//Debug
//0 = off (for production use)
//1 = client messages
//2 = server and client messages
//$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.yandex.ru';
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setLanguage('ru');
$mail->setFrom('', '');
$mail->addAddress('', ''); //Recipient
//$mail->addAddress('[email protected]');
//$mail->addCC('[email protected]'); //Copy
//$mail->addBCC('[email protected]'); //Bcc
//$mail->addAttachment('/path/to/file.zip'); //Attach file
//$mail->addAttachment('/path/to/image.jpg', 'new.jpg'); // Attach file + set name
$mail->isHTML(true);
$name = $_POST['name'];
$eemail = $_POST['eemail'];
$comments = $_POST['comments'];
$mail->Subject = 'Subject from $name $eemail ';
$mail->Body = 'New ticket from the site\n Name: $name\nEmail: $eemail\nMessage: $comments';
$mail->AltBody = 'Text version of the mail, without HTML tags (for clients that do not support HTML)';
//Send message
if(!$mail->send()) {
echo 'Error sending. Mistake: ' . $mail->ErrorInfo;
} else {
echo 'Message sent successfully';
}
?>
Answer the question
In order to leave comments, you need to log in
Take the variables out of brackets, i.e.:
$name = $_POST['name'];
$eemail = $_POST['eemail'];
$comments = $_POST['comments'];
$mail->Subject = 'Заявка от '.$name.' '.$eemail;
$mail->Body = 'Новая заявка с сайта\n Имя:'. $name.'\nEmail:'. $eemail.'\nСообщение:'. $comments;
$mail->AltBody = 'Текстовая версия письма, без HTML тегов (для клиентов не поддерживающих HTML)';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question