I've made a HTML email and everything has worked so far. I was planning to send it with PHP (using the mail(); function). However, when I did this, the mail did not arrive at hotmail and gmail accounts. I googled around a bit and people suggested to use PHPmailer.
I downloaded PHPmailer and installed it on my server. So far, so good. But now I have the following code:
<?php
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\phpmailer.inc.php');
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\smtp.inc.php');
require("phpmailer.inc.php");
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->From = "from@example.com";
$mail->AddAddress("mymail@mydomain.com");
$mail->Subject = "An HTML Message";
$mail->Body = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";
if($mail->Send()) {
echo 'Message is sent';
} else {
echo 'Message was not sent..';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>
I got several problems:
- The output tells me the email is not sent, but it is.
- I get two subjects
- If I add more html (like a table), it still gets rejected by hotmail (and probably gmail too).
Also, I saw there's a SMTP function. How to use this function? Do I need to write down my own SMTP?
Would be very happy if someone could help me out!
edit:
class SMTP {
var $SMTP_PORT = 25; # the default SMTP PORT
var $CRLF = "\r\n"; # CRLF pair
var $smtp_conn; # the socket to the server
var $error; # error if any on the last call
var $helo_rply; # the reply the server sent to us for HELO
var $do_debug; # the level of debug to perform
/*
* SMTP()
*
* Initialize the class so that the data is in a known state.
*/
function SMTP() {
$this->smtp_conn = 0;
$this->error = null;
$this->helo_rply = null;
$this->do_debug = 0;
}