PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 31, 2022

[FIXED] How to send html email?

 August 31, 2022     pear, php     No comments   

Issue

I need to send html email. So I am using PEAR library with Mail extension

So I have written this code:

include('Mail.php');
include('Mail/mime.php');

$email = "xxx@gmail.com";
$from_addr = "example <yyy@gmail.com>";
$message_subject ="Test";    
$text =  "
Hello.
This is a link:

http//:www.hardevent.net/index.php

byebye
";

$html = "<html>
<body>
<p>
Hellooooo, this is a link:
</p>
<a href=\"http://www.google.com\"/>Gooooo</a>
</body>
</html>";

                     $headers = array ("From" => $from_addr,
                                       "To" => $email,
                                       "Subject" => $message_subject);


                     $crlf = "\n";
                     $mime = new Mail_mime($crlf);
                     $mime->setTXTBody($text);
                     $mime->setHTMLBody($html);
                     $body = $mime->get();
                     $hdrs = $mime->headers($headers);
                     $smtp = Mail::factory("smtp", array ('host' => "smtp.xxx.com",
                                                          'auth' => true,
                                                          'username' => "xxx",
                                                          'password' => "xxx"));
                     $mail = $smtp->send($email, $hdrs, $body);

But this is the email that I see ( only text without link ):

Object: Test
Hellooooo, this is a link:

Gooooo

why ?


Solution

Typo?

<a href=\"http://www.google.com\">Gooooo</a>


Answered By - Tommy
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing