-4

I am working with phpmailer and trying to send an email with attachment but email is not working (no email sending) as well as attachment.

require_once 'phpmailer/class.phpmailer.php';
if (isset($_REQUEST['FindDealer'])) {
    $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
    $mail->SetFrom('name@yourdomain.com', 'First Last');
    $mail->AddReplyTo('name@yourdomain.com', 'First Last');
    $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
    $mail->AltBody = 'To view the message,
    $mail->MsgHTML(file_get_contents('contents . html'));
    $email->AddAttachment( $file_to_attach , 'pdf . pdf);
    return $email->Send();
    exit;
}

Please guide me about this ..

Ryan Vincent
  • 4,310
  • 7
  • 19
  • 29
usman
  • 63
  • 9

1 Answers1

0

you used every line the variable $mail except on these lines:

$email->AddAttachment( $file_to_attach , 'pdf . pdf);
return $email->Send();

change them to the following and it should working:

$mail->AddAttachment( $file_to_attach , 'pdf . pdf);
return $mail->Send();

EDIT: And fix the errors (see on the syntax highlighting):

require_once 'phpmailer/class.phpmailer.php';
if (isset($_REQUEST['FindDealer'])) {
    $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
    $mail->SetFrom('name@yourdomain.com', 'First Last');
    $mail->AddReplyTo('name@yourdomain.com', 'First Last');
    $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
    $mail->AltBody = 'To view the message, ';
    $mail->MsgHTML(file_get_contents('contents . html'));
    $mail->AddAttachment( $file_to_attach , 'pdf . pdf');
    return $mail->Send();
    exit;
}
Sebastian Brosch
  • 37,059
  • 14
  • 61
  • 73