0

I am using pear lib for sending an email and getting three issues when I am sending any emails from Gmail using PHP.

1) I am getting HTML code in the email.

2) If I am using any anchor element then email delivery failed.// without anchor element it is working.

3) The anchor element link is not working in iPhone.// for iPhone i tried

require_once "mail/Mail.php";
  $to = $email;
  $from = 'user@gmail.com';
  $subject = 'Test!';
  $body = "<html><head><title>HTML email</title></head>
        <body>
        <a href='domain.com/changepassword.php?user_id=" .$User_id1."'>Create your password here</a>
        </body>
        </html>";// HTML code is display in email
       $headers = array(
           'From' => $from,
            'To' => $to,
            'Subject' => $subject
        );
   $smtp = Mail::factory('smtp', array(
                'host' => 'ssl://smtp.gmail.com',
                'port' => '465',
                'auth' => true,
                'username' => 'user@gmail.com',
                'password' => '******'
            ));

    $mail = $smtp->send($to, $headers, $body);
        if (PEAR::isError($mail)) {
            echo('<p>' . $mail->getMessage() . '</p>');
        } else {
            echo('<p>Message successfully sent!</p>');
        }
John
  • 1
  • 13
  • 98
  • 177

2 Answers2

2

You have to define in header for html. Hope you will get solution here: how to send html mails using PEAR mail

Add http in link to make it workable for all cases.

I use phpmailer which is always fine. You can try this one. https://github.com/PHPMailer/PHPMailer

Community
  • 1
  • 1
Mehedee
  • 336
  • 1
  • 9
  • Thanks for reply Mr.Mehedee, Before I tried PHP mailer but my all emails goes to spam –  Jan 03 '17 at 10:15
  • Using smtp server resolves this issue. You can ask your server admin to get smtp server or you can use 3rd party smtp like pepipost.com but it will take time to approve. – Mehedee Jan 03 '17 at 10:22
  • I am using Gmail for sending mail using PHP –  Jan 03 '17 at 10:24
  • Strong filtration is used there - whitelist, redlist email. In some cases spam filter consider gmail as spam. You can test your from email here. Then you can understand clearly https://www.mail-tester.com/ – Mehedee Jan 03 '17 at 10:29
  • Mr.Mehedee you can check my PHPMailer code here http://stackoverflow.com/questions/41361169/sending-email-from-php-using-smtp-and-email-goes-to-spam-what-will-be-easiest-wa –  Jan 03 '17 at 10:40
  • I don't know why my all emails goes to spam –  Jan 03 '17 at 10:41
  • Why it is not working check here mail-tester.com. It will provide analysis report of your email. How you test: 1. send email to "web-r1ief@mail-tester.com" from your script. 2. Then click on button to see analysis report. Also you can try with email containing same domain. Your server admin will suggest. – Mehedee Jan 03 '17 at 11:08
  • Mr.Mehedee i tried on http://mailtester.com/ and it showing some message Server doesn't allow e-mail address verification in yellow color –  Jan 03 '17 at 11:51
1

How about trying this in your $body. Also remember that there should be no spaces after $body line (where DOCTYPE is declared).

I used this on SendGrid and PHPMailer.

$body = <<<EOD
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    Your content here
  </body>
</html>
EOD;
Nick
  • 21
  • 3
  • Thanks for reply Nick, I tried but still getting HTML code in email –  Jan 03 '17 at 10:06