0

I have problem with mail function and PHPMailer package on my site.

at first i tried to send email with mail function:

mail('myemail@gmail.com', 'Test Mail - Raw', 'Test message.');

mail has been sent successfully but not received in my inbox or spam.

after a lot of search i add a header to mail function:

mail('myemail@gmail.com', 'Test Mail - Without Reply-To', 'Test message', "From: mahdyaslami <myemail@gmail.com>");

and finally i found my sent mail in spam with a yellow warning.

i want to user PHPMailer package because i want to attach file and i add this code.

protected function send($from, $to, $subject, $body, $altBody, $attachmentPath): bool
{
    // Instantiation and passing `true` enables exceptions
    $mail = new PHPMailer(true);
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;
    $mail->SMTPSecure = 'ssl';
    $mail->isSMTP();
    $mail->isSendmail();

    $mail->setFrom($from);
    $mail->addReplyTo($from, $from);
    $mail->addAddress($to);
    $mail->isHTML(true);

    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AltBody = $altBody;

    if ($attachmentPath) {
        $mail->addAttachment($attachmentPath);
    }

    $mail->send();
    return true;
}

but i have first problem, my mail has been sent successfully but i can not receive mail in my inbox or spam.

Mahdi Aslami Khavari
  • 1,755
  • 15
  • 23
  • 1
    If your mail has been successfully sent you can't do anything more? The mailserver that recieves the mail has to take care of the recieving part :-) Maybe you could add more text beside the attachment because only sending a big attachment would make mailservers say "hay this is spam" – bestprogrammerintheworld Apr 16 '20 at 04:39
  • Your code has no error checking or debug output, so you have no way to tell if or how it’s failing. Start again with one of the examples provided with PHPMailer which does do that and may find more evidence for what’s going on. You are sending in a completely different way - these code samples are in no way equivalent. – Synchro Apr 16 '20 at 05:09

0 Answers0