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(); } } 
  • Themselves debugger passed? Accurately gets inside if where $mail->AddAttachment ? - AK ♦
  • one
    And what's the point of doing AddAttachment after Send ? - Small
  • @AK yes hits. - Victor
  • @ Small AddAttachment comes before Send . What do you have in mind? - Victor
  • @Victor $mail->Send(); if (isset($_FILES['file']) $mail->Send(); if (isset($_FILES['file']) ;) - E_p

0