Hi guys, I have been using the mail() command to send HTML formatted email for a while now. I simply add the appropriate headers and it works. I recently moved my hosting from a shared hosting plan with GoDaddy to a Virtual Dedicated Server with GoDaddy and this stopped working?? The emails now go out fine but instead of going out as an HTML email, the receiver receives the actual HTML code displayed in their email. Has anybody else come across something similar?? Please help. Regards, dfsweb
Use PHPmailer class instead mail() This is excellent and easy way to send mail. You can find it here — phpmailer.sourceforge.net
I am using these headers: $headers="From: \r\n"."Reply-To: \r\n"."Content-Type: text/html;\r\n charset=\"ISO-8859-1\"\r\n"; mail($email_address,$subject,$complete_body,$headers);
dfsweb, I would follow vvooles advice and use PHPmailer, its just a basic call to a class and exceptionally powerful for sending HTML embedded email.
Can PHPMailer be used for sending multiple emails. I need to send out a newsletter to around 3,000 members in my database that are split into mailing lists of 750 each. Can somebody please post a basic script for sending an email using this command to one as well as more than one person? I would really appreciate this. I saw the example on the URL mentioned above but it had a lot of options that I don't need. I just want to send out a basic email (no attachments). Thanks! dfsweb
I use something like that: <?php require_once('phpmailer.class.php'); /*** Mail settings ***/ $M['method'] = 'mail'; // mail or smtp $M['fromname'] = 'From Name'; $M['from'] = 'no-reply@site.com'; $M['admin'] = '11111@2222222.com'; $M['lang'] = 'phpmailer.lang-en.php'; class Mailer extends PHPMailer{ var $WordWrap = 75; function Mailer(){ global $M; include($M['lang']); $this->language = $PHPMAILER_LANG; $this->Mailer = $M['method']; if($M['method']=='smtp') $this->Host = $M['smtphost']; } function send2user($to, $subject, $body){ global $M; $this->ClearAddresses(); $this->ClearAttachments(); $this->Subject = $subject; $this->Body = $body; $this->AddAddress ($to); $this->FromName = $M['fromname']; $this->From = $M['from']; $this->send() || add_log("$this->ErrorInfo\n\n$subject\n$body"); } } function add_log($log){ // put action for log here } /*** Database connect ***/ $con = mysql_connect('localhost', 'name', 'pass'); mysql_select_db('database',$con); $query = "SELECT email FROM newsletter"; $result = mysql_query($query); /*** Sending ***/ if ($result){ $mailagent = new Mailer(); while($row = mysql_fetch_row($result)){ $mailagent->send2user($row[0], 'put subject here', 'put letter here'); } } ?> Code (markup): Note that this is crude code. Actually I split it in some files — mailer.class.php, setting.php and action.php for example. Also I set mark in database if letter is sent successfully or not, set the time of last sending and other useful things.
you can use header type too $email = abc@yahoo.com $headers = "from:".$email; $headers .= "Content-Type: text/html; charset=us-ascii\n"; $headers .= "Content-Transfer-Encoding: 7bit"; mail("toemail","Subjectl","message",$headers); echo "<br>"; PHP:
may be it's a domain problem, did you set up all corresponding redirections for your domain name on your new hosting plan: such as: smtp.yourdomain.com
I tried just about everything to make this work guys, with no luck. I had almost given up when I sent a test email to my Yahoo account and it worked! It seems that for some reason emails that are being sent intra-server, i.e. from the server to any of my email addresses that are hosted on that server, I can see the HTML code instead of the normal HTML. But, if I email myself on an external email address, it is working like it should. Not sure why Regards, dfsweb
Just my 2 (euro)cents: if you plan to send newsletters and mails to a large userbase I would set up a cron job that does this on smaller chunks of users and on a timely basis (say 200 emails per minute) Also, as stated here: http://php.net/manual/en/function.mail.php (in the notes), the best way to send large amounts of email is using PEAR::Mail: http://pear.php.net/package/Mail Cheers!
Why not give a try to phplist - this works all the time! It is prebuilt - you don't have to worry about coding - unless if you love coding