0

I have a bit of a strange one. Using PHP Pear Mail I am sending an HTML email with a link in to a subdomain http://mysub.mydomain.co.uk

$body='<html><body><strong>Hello '.$forename.'</strong><br><br>Thank you for registering your details. To complete the process, please follow the link below in this email.<br><br>
    <a href="http://mysub.mydomain.co.uk?V='.$myvalue.'">Complete Verification Here</a></body></html>';
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$mime = new Mail_mime();
$mime->setHTMLBody($body); 
$headers = $mime->headers($headers); 
$smtp = Mail::factory('smtp', 
        array ('host' => $host,
            'auth' => true,
            'username' => $username,
            'password' => $password)
        );
$mail = $smtp->send($to, $headers, $body); 

The email gets sent fine and if I print the body of the email onto the screen from the page sending the email the link works fine. However when it arrives in an email in MS outlook it is taking the first 2 characters out of myvalue in the link. If myvalue=12345678 it says myvalue=345678 and displays the link incorrectly for example it shows the above as ttp://mysub.mydomain.co.uk/?V=345678. Notice it removes the H in the http address and also adds a forward slash before the ?v= and the first 2 digits 12 are also missing. It then fails to open the link as it is displaying it incorrectly as a http link. The email also does not arrive as an HTML email at Gmail and there is no link.

Any idea what I am missing here?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Patdundee
  • 161
  • 2
  • 10
  • This might be the same problem as http://stackoverflow.com/questions/31227537/dot-s-are-missing-here-there-in-the-mail-html-while-sending-pear-mail-mime-e – cweiske Sep 20 '15 at 12:51

2 Answers2

0

Eventually found the issue

In the body text I had to replace every occurrence in the body of

"

with ASCII code

&#039

Now working fine

Patdundee
  • 161
  • 2
  • 10
0

You don't have to manipulate the body text outside of the mail_mime package, you need to mime encode the body with it:

$mime = new Mail_mime();
$mime->setHTMLBody($body);
$mimebody = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory(
    'smtp',
    [
        'host' => $host,
        'auth' =>     true,
        'username' => $username,
        'password' => $password,
        'port' => $port
    ]
);

// send email
$mail = $smtp->send($to, $headers, $mimebody);
kguest
  • 3,804
  • 3
  • 29
  • 31