Mail function not working

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
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Mail function not working

Post by vipul73 »

Hi I am newbie to php and am trying to do a site for my alumni

i downloaded a alumni script but am not getting a mail when a user registers. The code is as below:

Code: Select all

$subject1="New Alumni registration";
      $message1="A new member has registered on the alumni website \n\n First Name: $fname\n\n Surname: $sname\n\n Present Surname: $nsname\n\n Year left: $leave\n\n e-mail address: $mail\n\n Postal Address:\n$add";
      mail($Mail, $subject1, $message1,"From: $mail");
I contacted my webspace provider and he has suggested to put as:

Code: Select all

<?php
require_once "Mail.php";
 
$from = "name Sender <mail@domain.com>";
$to = "name Recipient <mail@domain.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
 
$host = "mail.domain.com";
$username = "smtp_username";
$password = "smtp_password";
 
$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));
 
$mail = $smtp->send($to, $headers, $body);
 
 }
?>
 


How do i merge both the codes? Can someone please help. I tried doing but it is not working.
Last edited by Benjamin on Tue May 26, 2009 10:35 am, edited 1 time in total.
Reason: Changed code type from text to php.
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Re: Mail function not working

Post by vipul73 »

I have file by the name of forgot.php and am using the following code:

Code: Select all

 
<?php
require_once "Mail.php";
$db=mysql_connect("$Sname","$Uname","$Pname");
mysql_select_db("$Dname",$db); 
 
if ($sub) {
 
   // send information to owner
 
        $sql="SELECT * FROM $Tname WHERE email='$imail'";
        $result=mysql_query($sql);
   if ($myrow = mysql_fetch_array($result)) {
        $subject="$School alumni register";
        $message="$School alumni, this is your username and password which you will need to change your details or to send e-mails to other member.\n\n Username:   $myrow[username]\n\n Password:   $myrow[password]";
        $host = "mail.greatindian.org";
        $username = "alumni";
        $password = "pass888";
        $smtp = Mail::factory('smtp',
            array ('host' => $host,
            'auth' => true,
            'username' => $username,
            'password' => $password));
        $mail = $smtp->send($imail, $subject, $message,"From: $Mail");
 
      ?>
I am getting the error:

Warning: Invalid argument supplied for foreach() in /usr/local/lib/php/Mail.php on line 123

Warning: Invalid argument supplied for foreach() in /usr/local/lib/php/Mail.php on line 151

I urgently need help!
Post Reply