-2

i want to send email using user's entered email address to my email address using PHPMailer and without SMTP. But it takes too much time to send email and once it sent email i got mail in spam instead of inbox. Below is my complete code-

<?php 
session_start();
require_once 'class.phpmailer.php';
$mail = new PHPMailer;

$mail->From = $_POST['email'];
$mail->FromName ='Contacted By : '.$_POST['fname'];

$mail->addAddress("dev5.veomit@gmail.com"); 

$mail->addReplyTo($_POST['email'], "Reply");

$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<b>Name : </b>".$_POST['fname'].'<br/><b>Email Address : </b>'.$_POST['email'].'<br/><b>Message : </b>'.$_POST['msg'];
$mail->AltBody = "This is the plain text version of the email content";

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    $_SESSION['sucess-email']='You Have Contacted Successfully.';
    header("Location: https://m-expressions.com/test/voy/");
}
 ?>

Please help me solve this problem and thanks in advance.

Dev5
  • 67
  • 2
  • 10

1 Answers1

0

First of all you are using a very old version of PHPMailer; Update to the latest version.

While you say it's slow, you don't say how slow - 1 second? 30 seconds? 10 minutes? You are sending using the default mail() transport, which means you are submitting to a local mail server - which may be misconfigured or slow, but that's outside PHPMailer's area of responsibility.

You are forging the "from" address which (if your mail server allows you to do it at all), will result in failing SPF checks, which will usually put you into the spam folder. Do this instead:

$mail->setFrom('me@example.com', 'My Name');
$mail->addAddress('me@example.com');
$mail->addReplyTo($_POST['email']);

That is, send from yourself, to yourself, but using a reply-to of the submitter. This way replies to the message will go to the submitter, but you're not forging the from address.

I suggest you start again using the contact form example provided with PHPMailer.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • it is giving me 500 error – Dev5 Jun 07 '19 at 06:59
  • So enable debug output or check your web server's error log to see where the problem is. Make sure you are including the classes correctly, either by using composer or loading them manually, as described in the project readme. – Synchro Jun 07 '19 at 07:01