user6930268
user6930268

Reputation:

Mail Delivery failed when using anchor element in HTML email using PHP

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 = '[email protected]';
  $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' => '[email protected]',
                'password' => '******'
            ));

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

Upvotes: 0

Views: 715

Answers (2)

Mehedee
Mehedee

Reputation: 336

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

Upvotes: 2

Nick
Nick

Reputation: 21

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;

Upvotes: 1

Related Questions