Page 1 of 1

PHP Help

Posted: Fri May 22, 2009 2:13 pm
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

Re: PHP Help

Posted: Fri May 22, 2009 2:22 pm
by anand
Maybe your email client blocked all mails from your server.

Do you get echo SUCCESS ?

Re: PHP Help

Posted: Fri May 22, 2009 2:31 pm
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.

Re: PHP Help

Posted: Fri May 22, 2009 2:37 pm
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.

Re: PHP Help

Posted: Fri May 22, 2009 2:51 pm
by hummy
no that doesn't seem to have any affect. It says success but the mail has not come thru.

Re: PHP Help

Posted: Fri May 22, 2009 3:02 pm
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) ;