Help please - I can not understand the reason. Data from the fields are sent to the mail and the application is not. PhpMailer installed through the composer. Implementation on MVC.
Thanks for the help!
Model:
<?php class Mail{ public static function sendOneEmail($email, $subject, $body){ $mail = new PHPMailer(); //ΡΠΎΠ·Π΄Π°Π΅ΠΌ ΡΠΊΠ·Π΅ΠΌΠΏΠ»ΡΡ ΠΊΠ»Π°ΡΡΠ° $mail->addAttachment($path); $mail->IsSMTP(); //Π²ΠΊΠ»ΡΡΠ°Π΅ΠΌ SMTP $mail->Host = 'smtp.yandex.ua'; $mail->SMTPAuth = true; // Π²ΠΊΠ»ΡΡΠ°Π΅ΠΌ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΡ ΠΏΠΎ SMTP $mail->Port = 587; // 465 or 587 ΡΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ SMTP ΠΏΠΎΡΡ $mail->Username = '559912@yandex.ru'; //Π²Π°ΡΠ° ΠΏΠΎΡΡΠ° $mail->Password = 'qwerty'; //ΠΏΠ°ΡΠΎΠ»Ρ $mail->SetFrom('559912@yandex.ru'); //$mail->AddReplyTo(('email@yandex.ru', 'ΠΠ°ΡΡ ΠΡΠΏΠΊΠΈΠ½'); $mail->IsHTML(true); // ΠΎΡΠΏΡΠ°Π²ΠΊΠ° Π² Π²ΠΈΠ΄Π΅ HTML $mail->CharSet='utf-8'; //ΠΊΠΎΠ΄ΠΈΡΠΎΠ²ΠΊΠ° ΠΏΠΈΡΡΠΌΠ° $mail->Subject = $subject; $mail->SMTPSecure = 'tls'; $mail->Body = $body; $mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only $mail->AddAddress($email); $mail->Send(); if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK) { $mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']); } } } Controller:
<?php class ContactsController extends Controller{ public function __construct($data = array()){ parent::__construct($data); $this->model = new Message(); } public function index(){ if ( $_POST ){ $mail = new Mail(); $company_name = htmlspecialchars(trim($_POST['company_name'])); $contact_name = htmlspecialchars(trim($_POST['contact_name'])); $phone = htmlspecialchars(trim($_POST['phone'])); $email = htmlspecialchars(trim($_POST['email'])); $file = htmlspecialchars(trim($_POST['file'])); $message = "ΠΠ°Π·Π²Π°Π½ΠΈΠ΅ ΠΊΠΎΠΌΠΏΠ°Π½ΠΈΠΈ: $company_name"."<br>"."ΠΠΎΠ½ΡΠ°ΠΊΡΠ½ΠΎΠ΅ Π»ΠΈΡΠΎ: $contact_name"."<br>"."ΠΠΎΠ½ΡΠ°ΠΊΡΠ½ΡΠΉ ΡΠ΅Π»Π΅ΡΠΎΠ½: $phone"."<br>". "E-mail: $email"."<br>"."ΠΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅: $file"."<br>"; $message = wordwrap($message, 70, "\r\n"); Mail::sendOneEmail('559912@yandex.ru', 'ΠΠ°ΡΠ²ΠΊΠ°', $message); header("Location: /?success"); } } public function admin_index(){ $this->data = $this->model->getList(); } }
$mail->AddAttachment? - AK β¦AddAttachmentafterSend? - SmallAddAttachmentcomes beforeSend. What do you have in mind? - Victor$mail->Send(); if (isset($_FILES['file'])$mail->Send(); if (isset($_FILES['file']);) - E_p