-1

I have try to send mail using php, but mail goes to spam Below is my code

 //send mail
    $from = get_option('client_mail');
    $to = $_POST['email'];
    $subject = get_option('subject_');
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From:".$from."\r\n";
    $message1= "<html>
    <body>
    <table width='100%' border='0'>
    <tr>
    <td>here is my is mail ending code
    </td>
    </tr>
    </table>
    </body>
    </html>";
    if(mail($to,$subject,$message1,$headers))
    {
        $yes = 'mail send';
    }
    else
    {
        $yes = 'mail not send';
    }

After process i got "mail send". And i also try PHPMailerAutoload here is code

  if( file_exists("PHPMailer-master/PHPMailerAutoload.php") && is_readable("PHPMailer-master/PHPMailerAutoload.php") && include("PHPMailer-master/PHPMailerAutoload.php")) {

                //mail sending
                $email = new PHPMailer();
                $email->From      = 'from_email';
                $email->FromName  = 'fname';
                $email->Subject   = 'mail attarchment';
                $email->Body      = 'after remove atachment';
                $email->AddAddress( 'to_email' );


               if(!$email->send()) {
                   echo 'Message could not be sent.';
                   echo 'Mailer Error: ' . $mail->ErrorInfo;
               } else {
    echo 'Message has been sent';
               }
                }

And here is got after mail process "Message has been sent"

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

while using php mailer you have to use smtp mode.then it will not go to spam here they discribe in breif how to use php mailer with smtp mode

 require_once('class.phpmailer.php');
    function sendmail($to,$subject,$message,$name)
    {
                  $mail             = new PHPMailer();
                  $body             = $message;
                  $mail->IsSMTP();
                  $mail->SMTPAuth   = true;
                  $mail->Host       = "smtp.gmail.com";
                  $mail->Port       = 587;
                  $mail->Username   = "youraccount@gmail.com";
                  $mail->Password   = "your gmail password";
                  $mail->SMTPSecure = 'tls';
                  $mail->SetFrom('youraccount@gmail.com', 'Your name');
                  $mail->AddReplyTo("youraccount@gmail.com","Your name");
                  $mail->Subject    = $subject;
                  $mail->AltBody    = "Any message.";
                  $mail->MsgHTML($body);
                  $address = $to;
                  $mail->AddAddress($address, $name);
                  if(!$mail->Send()) {
                      return 0;
                  } else {
                        return 1;
                 }
    }
sendmail("mailto@example.com","example subject","dummy message","dummy name");

refference: https://codeforgeek.com/2014/11/phpmailer-ultimate-tutorial/

Varun Malhotra
  • 1,202
  • 3
  • 15
  • 28
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/15628295) – manniL Mar 24 '17 at 11:29
  • ok i will do that and try to keep this in mind while giving answer. – Varun Malhotra Mar 24 '17 at 11:38