Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-08-2011, 08:54 AM   PM User | #1
silviadec
New to the CF scene

 
Join Date: Jun 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
silviadec is an unknown quantity at this point
php mailer with html

Hi!
I need some help... I have this php email, It works fine (very simple and clean): when somebody sends me and email from my website, I receive the his info and he receives an autoresponder email with the mail confirmation.

Now, I'd love to send the auto responder as an html email, with logo image in the body of the email.

Could you help me? I tried everything I found on the web, but it doesnt work!

this is the code I have:

PHP Code:

<?php
    
function anti_spam($str) {
        
$str strtolower($str);
        
$str trim($str);
        if (
$str == || $str == '2' || $str == 'two') {
            return 
TRUE;
        } else {
            return 
FALSE;
        }
    }
          if(isset(
$_POST['submit'])) {
          
error_reporting(E_NOTICE);
          function 
valid_email($str)
          {
          return ( ! 
preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix"$str)) ? FALSE TRUE;
             }
          if(
$_POST['name']!='' && anti_spam($_POST['antispam'])==TRUE &&  $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)
          {
        
$to preg_replace("([\r\n])"""$_POST['receiver']);
        
$from preg_replace("([\r\n])"""$_POST['name']);
        
$subject $_POST['subject'];
        
$email $_POST['email'];
        
$telefono $_POST['telefono'];
        
$comment $_POST['comment'];
        
$time date('j F, Y g:i a'time());
        
        
$message "Da: $from  \r\nData Invio: $time \r\nTelefono: $telefono \r\nOggetto: $subject \r\nMessaggio: $comment";
             
$autoTo $_POST['email'];
$autoreply "Salve $from,\n\rQuesto è un risponditore automatico.\n\rAbbiamo ricevuto la sua richiesta.\n\rLa contatteremo quanto prima!\n\rGrazie!\n\r";  //change this to your message

mail($autoTo"Richiesta inoltrata con successo!"$autoreply'From: myemail@email.com');

             
              
$match "/(bcc:|cc:|content\-type:)/i";
                if (
preg_match($match$to) ||
                    
preg_match($match$from) ||
                    
preg_match($match$message) || preg_match($match$subject)) 
            
                {
                  die(
"Header injection detected.");
                }
              
$headers "Da: \"".$_POST['name']."\" <".$_POST['email'].">\n";
                 
$headers .= "Rispondi a: ".$_POST['email']."\r\n";
             
        if(
mail($to$subject$message$headers))
              {
                  echo 
1//SUCCESS
              
}
              else {
                  echo 
2//FAILURE - server failure
              
}
          }
          else {
             echo 
3//FAILURE - not valid email

          
}
          }else{
             die(
"Direct access not allowed!");
           }
?>


Thank you!!!
silviadec is offline   Reply With Quote
Old 06-08-2011, 04:49 PM   PM User | #2
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
For sending html with email.

PHP Code:
<?
$from 
"email from";
 
$to "sent to";
 
$subject "test";
 
$body "<html><body><font color=red>This is a test</font></body></html>";
 
 require_once(
"class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->IsHTML(true);
$mail->SMTPAuth true;
$mail->Username "your SMTP username"
$mail->Password "your SMTP password"
$mail->Host "SMTP server"// 
$mail->From $from;
$mail->AddAddress($to);
$mail->Subject $subject;
$mail->Body $body;
if(!
$mail->Send()) {
  echo 
'Message was not sent.';
  echo 
'Mailer error: ' $mail->ErrorInfo;
} else {
echo 
'Message has been sent successfully';
    }

?>
class.phpmailer.php can be gotten here: http://www.phpclasses.org/package/26...s-for-PHP.html
__________________
If you can't stand behind your troops, feel free to stand in front of them
Semper Fidelis
jimhill is offline   Reply With Quote
Old 06-09-2011, 06:17 AM   PM User | #3
silviadec
New to the CF scene

 
Join Date: Jun 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
silviadec is an unknown quantity at this point
Thank you so much for your reply, but where do I insert this code you sent me?
silviadec is offline   Reply With Quote
Reply

Bookmarks

Tags
php mailer, send html email with php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:42 PM.


Advertisement
Log in to turn off these ads.