Jump to content

mail script html images help


calmchess

Recommended Posts

I'm useing this script to send mail which works fine my question is how do I send html and Images within  the body of the email?

 

<?php

function sdmail(){

require_once ("../secure_php/Mail.php");

$recipients=$_POST['email'];

//$from = $_POST[auth0];

$from = "[email protected]";






//$subject = $_POST[sub0];

$subject = "test";






$body = "test";



//$host = $_POST[host0];

$host = "smtp.somehost.net";





//$username = $_POST[user0];

$username = "calmchessplayer";



//$password = $_POST[pass0];

$password = "password";





$headers = array ('From' => $from,

  'To' => $recipients,

  'Subject' => $subject);

  

$smtp = Mail::factory('smtp',

  array ('host' => $host,
    

    'auth' => true,

    'username' => $username,

    'password' => $password));

$mail = $smtp->send($recipients, $headers, $body);


}

?>

Link to comment
https://forums.phpfreaks.com/topic/154408-mail-script-html-images-help/
Share on other sites

I've done a bit of digging too and as is often the case with PEAR the documentation seems to be lacking.

 

If it is at all possible for you to switch to phpmailer there's plenty of examples here:

http://phpmailer.codeworxtech.com/index.php?pg=examples

 

including:

http://phpmailer.codeworxtech.com/index.php?pg=exampleamail

I now can send html using the following script my problem is I want to send an image with the html and plain text ....I've googled it extensively but i can't find the solution.Could somebody help me with sending a half plain text and half html message.....An image too would be nice but not necessary.

$message = new Mail_mime();
   $text = "the html message is as follows.";
   $html = "<html></body><h1>this is an html test</h1></body></html>";

   $message->setTxtBody($text);
   $message->setHTMLBody($html);
   $body = $message->get();
   $extraheaders = array("From"=>$from, "Subject"=>$subject);
   $headers = $message->headers($extraheaders);

ok I have the image part working using the following script but I still need to know how to send part html and part plain text.

 

$message = new Mail_mime();
   $text = "the html message is as follows.";


   $message->setTxtBody($text);
   $message->addHTMLImage("../Images/atomic.gif","image/gif","atomic",true); 
   $cid=$message->_html_images[count($message->_html_images)-1]['cid'];
   $html = '<html></body><h1>this is an html test</h1><img src="cid:'.$cid.'"></body></html>';
   $message->setHTMLBody($html);
  
   $body = $message->get();
   $extraheaders = array("From"=>$from, "Subject"=>$subject);
   $headers = $message->headers($extraheaders);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.