By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,026 Members | 2,085 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,026 IT Pros & Developers. It's quick & easy.

Sending E-mail using PHPMailer()

KeredDrahcir
100+
P: 426
I'm trying to send an E-mail using PHPMailer and although everything look okay, it's not coming through. Can anyone help?
I'm posting my information from a form.
Expand|Select|Wrap|Line Numbers
  1.     require_once ("class.phpmailer.php");
  2.     $contact_id    = $_REQUEST['contact_id'];
  3.     $to_email = $_REQUEST['to_email'];
  4.     $id    = $_SESSION['id'];
  5.     $subject = $_REQUEST['subject'];
  6.     $body = $_REQUEST['body'];
  7.     $send_as_html = ($_REQUEST['send_as_html']==''?false:true);
  8.  
  9.     $mail_from_name = $_SESSION['name'];
  10.     $mail_from_email = $_SESSION['login'];
  11.  
  12.     $sql = "SELECT * FROM contact WHERE contact_id = $contact_id";
  13.     $result = mysql_query($sql,$db);
  14.  
  15.     $first_name    = mysql_result($result,0,'first_name');
  16.     $last_name     = mysql_result($result,0,'last_name');
  17.     $email = mysql_result($result,0,'email');
Then I try to send the E-mail
Expand|Select|Wrap|Line Numbers
  1.  
  2. <table border="1" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC">
  3. <?
  4.             $mail = new PHPMailer();
  5.             $mail->IsSMTP(true);
  6.             $mail->Host = 'localhost';
  7.             $mail->From = $mail_from_email;
  8.             $mail->FromName = $mail_from_name;
  9.             $mail->AddAddress($email);
  10.             $mail->AddBCC('myemail');
  11.             $mail->IsHTML($send_as_html);
  12.             $mail->Subject = $subject;
  13.             $mail->Body    = stripslashes($body);
  14.  
  15.             if($mail->Send())
  16.             {
  17. ?>
  18.               <tr>
  19.                 <td><?=$email;?></td>
  20.                 <td>Sent</td>
  21.               </tr>
  22. <?
  23.             }
  24.             else
  25.             {
  26. ?>
  27.               <tr>
  28.                 <td><?=$to_email?></td>
  29.                 <td>Failed [<?=$mail->ErrorInfo?>]</td>
  30.               </tr>
  31. <?
  32.             }
  33.             unset($mail);
  34. ?>
  35.           </table>
Is tells me the E-mail was sent, but doesn't come through. Any ideas?
Jun 8 '10 #1
Share this Question
Share on Google+
4 Replies


KeredDrahcir
100+
P: 426
Can anyone help please?
Jun 11 '10 #2

KeredDrahcir
100+
P: 426
can anyone suggest anything I could try if you need more information?
Jul 9 '10 #3

TheServant
Expert 100+
P: 1,168
Print all of your variables that are sent to the mail object and check they are what you expect. I will have a better look tomorrow... Must go to bed!
Jul 9 '10 #4

KeredDrahcir
100+
P: 426
Thanks. I'll try that when I'm back on Thursday.
Jul 9 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.