php mail not sending

Discussion in 'PHP' started by ashrafzia, May 20, 2008.

  1. #1
    Hi

    I am using the PHP mail function for sending e-mails but its not sending the mail and i m also not getting any error.

    Heres my code :

    
    <?php
    ob_start();
    session_start();
    include("menu.php");
    include("functions.php");
    show_header();
    error_reporting(E_ALL);
    
    //print "client id is : $_SESSION[client_id]";
    
    $to = "ashrafzia@yahoo.com";
    $subject = "Invoice Reminder";
    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    //'MIME-Version: 1.0'."\r\n".'Content-type: text/html; charset=iso-8859-1'."\r\n"
    
    // Additional headers
    $headers .= 'To: Ashraf <ashrafzia@yahoo.com>' . "\r\n";
    $headers .= 'From: Invoice Reminder <invoice@example.com>' . "\r\n";
    $headers .= 'Cc: invoice@example.com' . "\r\n";
    $headers .= 'Bcc: invoice@example.com' . "\r\n";
    
    
    $sql = "SELECT * from client_info, payments, services_ordered where client_info.client_id=$_SESSION[client_id] "; 
    //print "<br><br><br>".$sql;
    $res = mysql_query($sql) or die(mysql_error());
    while($row=mysql_fetch_assoc($res)){
    	$c_name = $row['f_name']." ".$row['l_name'];
    	$c_add = $row['address'];
    	$country = $row['country'];
    	$state = $row['state'];
    	$pcode = $row['p_code'];
    	$mob = $row['mob_ph'];
    	$ph = $row['hom_ph'];
    	$bank = $row['bank_name'];
    	$acc_name = $row['acc_name'];
    	$acc_no = $row['acc_no'];
    	$bsb = $row['bsb_no'];
    //	$s_date = $row['due_date'];
    	$a_name = $row['admin_name'];
    	$a_add = $row['admin_add'];
    	$c_no = $row['contact_no'];
    
    }
    
    $mailbody = "	<table align='center'>
    				  <tr>
    					<td><table>
    					  <tr>
    						<td colspan='2'><div align='center'><strong>Admin Details</strong></div></td>
    					  </tr>
    					  <tr>
    						<td>Name : </td>
    						<td>$a_name</td>
    					  </tr>
    					  <tr>
    						<td>Account No :</td>
    						<td>$acc_no</td>
    					  <tr>
    						<td>Address :</td>
    						<td>$a_add</td>
    					  </tr>
    					  <tr>
    						<td>Contact No : </td>
    						<td>$c_no</td>
    					  </tr>
    					  <tr>
    						<td>Bank Details : </td>
    						<td>$bank</td>
    						</tr>
    					  <tr>
    						<td>&nbsp;</td>
    						<td>&nbsp;</td>
    					  </tr>
    					  <tr>
    						<td>&nbsp;</td>
    						<td>&nbsp;</td>
    					  </tr>
    					</table></td>
    					<td><table>
    					  <tr>
    						<td colspan='2'><div align='center'><strong>Client Info </strong></div></td>
    					  </tr>
    					  <tr>
    						<td>Name:</td>
    						<td>$c_name</td>
    					  </tr>
    					  <tr>
    						<td>Address:</td>
    						<td>$c_add</td>
    					  </tr>
    					  <tr>
    						<td>Country:</td>
    						<td>$country</td>
    					  </tr>
    					  <tr>
    						<td>State:</td>
    						<td>$state</td>
    					  </tr>
    					  <tr>
    						<td>Post Code: </td>
    						<td>$pcode</td>
    					  </tr>
    					  <tr>
    						<td>Mobile No: </td>
    						<td>$mob</td>
    					  </tr>
    					  <tr>
    						<td>Phone No: </td>
    						<td>$ph</td>
    					  </tr>
    					</table></td>
    					  </tr>
    					  <tr>
    						<td colspan='5'><table width='100%' align='center'>
    						 <tr>
    							<td colspan='4'><div align='center'>
    							  <strong>Services Availed</strong>
    							</div></td>
    						  </tr>
    						  <tr class='trbg'>
    							<td><div align='left'><strong>Service Name</strong></div></td>
    							<td><div align='center'><strong>Date</strong></div></td>
    							<td><div align='center'><strong>Admin Comments</strong></div></td>
    							<td><div align='center'><strong>Adjusted Price </strong></div></td>
    							</tr>
    						  <tr>";
    //	$clientid = mysql_real_escape_string($_POST['c_id']);
      	$sql = "SELECT service_ordered, admin_comments, ordered_date, adj_price from services_ordered 
    				where services_ordered.client_id=$_SESSION[client_id]"; 
    	$res = mysql_query($sql) or die(mysql_error());
    	while($row=mysql_fetch_array($res)){
    			$s_names = $row['service_ordered'];
    			$d_date = $row['ordered_date'];
    			$a_comments = $row['admin_comments'];
    			$adj_price = $row['adj_price'];
    		
        $mailbody .="<td>$s_names</td>
    				<td>$d_date</td>
    				<td>$a_comments</td>
    				<td align='center'>$adj_price</td>
    				</tr>";
    	 }
    	  
    //	$clientid = mysql_real_escape_string($_POST['c_id']);
    	$sql = "SELECT SUM(adj_price) as tot_price	from services_ordered where services_ordered.client_id=$_SESSION[client_id]"; 
    		$res = mysql_query($sql) or die(mysql_error());
    		$row=mysql_fetch_array($res);
    		
    		$my_price = 0;
    		$my_price = $my_price + $row['tot_price'];
    /*		if (isset($my_price)){
    			echo "My Price is set: $my_price";
    		}
    */		
    	
    	$mailbody .="
    				  <tr>
    					<td colspan='3' class='trbg'><strong>Total Price: </strong></td>
    					<td align='center' class='trbg'><strong>$my_price</strong></td>
    				  </tr>	
    				</table></td>
    			  </tr>
    			</table>
    			</form>";
    
    echo "<br>";
    //echo "$mailbody";
    
    // Mail it
    
    $send = mail($to, $subject, $mailbody, $headers);
    
    if ($send) {
    	echo "<strong><center><h2>Mail sent</h2></center></strong>";
    }
    else {
    	echo "Error in Sending Mail";
    	}
    
    show_footer();
    ?>
    
    
    PHP:
    I don't know what's the problem, I have even tried using a simple mail using the mail() but no fruitful result.

    please help

    Thanks in advance
     
    ashrafzia, May 20, 2008 IP
  2. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #2
    If everything seems to be OK, then try to ask your hosting provider. Sometimes the problem lies in the server. Have you try to send a simple email (use the sample script from the manual)?
     
    goldensea80, May 21, 2008 IP
  3. ashrafzia

    ashrafzia Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, i have tried but still no result.
    :(
    I am very desperate
     
    ashrafzia, May 21, 2008 IP
  4. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    safe_mode is on or off?
     
    manilodisan, May 21, 2008 IP
  5. chenyaniv

    chenyaniv Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    maybe your hosting provider do not sopport emailing, try sending your emails throw other emails providers.
     
    chenyaniv, May 21, 2008 IP
  6. bjplink

    bjplink Peon

    Messages:
    243
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I agree with everyone else here. A lot of shared hosts either have limits on the number of calls that can be made with mail() per hour or don't allow it at all. It's a classic mechanism for spammers so not a lot of hosts allow free use of it.
     
    bjplink, May 27, 2008 IP
  7. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Chances are that you are using Windows or your server disabled mail() function.

    Peace,
     
    Barti1987, May 27, 2008 IP
  8. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #8
    er.. did you try :


    mail($to, $subject, $mailbody, $headers);

    instead of :

    $send = mail($to, $subject, $mailbody, $headers); ??
     
    nastynappy, May 27, 2008 IP
  9. shah baz

    shah baz Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    hi zia! i m new here. can u help me to understand all these process. advance thanks.:)
     
    shah baz, Nov 9, 2008 IP