PHP Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hummy
Forum Newbie
Posts: 3
Joined: Fri May 22, 2009 2:06 pm

PHP Help

Post by hummy »

Hi There,

I wonder if someone can help me. I'm not a coder by profession and i am learning PHP as i go along really as i've inherited a website since our developer left. One of the functions on our site is not working which is based on email notifications. I wonder if someone can help me diagnose where the problem is. I've tested that the SMTP and account details are fine by using Outlook to send a message using the same account details as well as using Telnet.

So a function has been created in the commonfunction.php file

Code: Select all

 
function site_mail1($from,$to,$subject,$body){
set_include_path('c:\php\pear');
require_once "Mail.php";
$host = "xx.xxx.xxx.xxx";
$port = "25";
$username = "xxx@xxxxxxxx.org.uk";
$password = "xxxxxxxxx";
 
$headers = array ('From' => $from,
 'To' => $to,
  'Subject' => $subject,
  'Content-Type' => 'text/html');
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));
    //echo $to."--<br>".$headers."--<br>".$body;
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
    //echo PEAR_Error::getMessage ($mail );
  return TRUE;
 } else {
  return FALSE;
 }
}
 
So to test the function i have just have created a test page with the following code:

Code: Select all

 
<?php
$docRoot = substr($_SERVER["SCRIPT_FILENAME"], 0, strlen($_SERVER["SCRIPT_FILENAME"]) - strlen($_SERVER["SCRIPT_NAME"]));
include ($docRoot ."/includes/config.inc.php"); 
$Name="Site Mail";
$from= "xxx@xxxxx.co.uk";
$to="xxxx@xxxx.com";
$bc="xxxx@xxxx.com";
                $subject= "[ ]"."A new message arrived in your message centre";
                    
                $body = '
<table width="500" border="1" cellpadding="0" cellspacing="0" bordercolor="#7A7A7A" align="center">
  <tr> 
                                          
    <td height="20" align="center" class="panel_head"><strong><font color="#000">Message Centre</font></strong></td>
                                        </tr>
                                        <tr>
                                          
    <td height="20" align="center" bordercolor="E7E7E7">A new message has arrived for you</td>
                                        </tr>
                                      </table>'; 
            if(site_mail1($from,$to,$subject,$body)){
                echo "SUCCESS";
            }else{
                echo "FAILURE";
            }
?> 
 
When i launch the test page it says success which indicates to me that a successful message has been sent but the message does not come thru.

If anyone can point me in the right direction that would be most helpful.

Thanks
Last edited by Benjamin on Fri May 22, 2009 3:33 pm, edited 1 time in total.
Reason: Added [code=php] tags.
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: PHP Help

Post by anand »

Maybe your email client blocked all mails from your server.

Do you get echo SUCCESS ?
hummy
Forum Newbie
Posts: 3
Joined: Fri May 22, 2009 2:06 pm

Re: PHP Help

Post by hummy »

yes i do get success...but don't receive the email.

Using the same settings i email myself from outlook and it works fine.
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: PHP Help

Post by anand »

Code: Select all

if(site_mail1($to, $subject, $body, $headers, "-f $from")){
 
/*
 
$to = mail where you want it to be sent
 
$subject = subject of your mail
 
$body = body of your mail
 
$headers = header. ( here you can include from tags)
 
$from = mail sent from */
 
 
Ok, Why don't you try this? This might help you.

I guess with your sendmail1 code, you are sending this mail to $from with subject $to.

Do check the $from mailbox once.
hummy
Forum Newbie
Posts: 3
Joined: Fri May 22, 2009 2:06 pm

Re: PHP Help

Post by hummy »

no that doesn't seem to have any affect. It says success but the mail has not come thru.
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: PHP Help

Post by anand »

hummy wrote:no that doesn't seem to have any affect. It says success but the mail has not come thru.
Normally mail function is mail($to, $subject , $body, $header , $from) ;
Post Reply