PHP Mail function - A little help?

Discussion in 'PHP' started by joshuaadams, Jul 5, 2012.

  1. #1
    Hi,

    I need a little help...

    I'm trying to enable an auto-mail function.

    What I want is whenever an admin post a completed project, it should automatically email the customer. I'm having problems with this code:


    
                        if($completed_file){
                        	move_uploaded_file($completed_file['tmp_name'], $dir.'/'.$completed_file['name']);
                        	$completed_filename = $completed_file['name'];
                        	$sql .= ",file = '".$completed_filename."', status = '0'";
    
    						
    						$sql	="SELECT * FROM `".CONFIG."`";
    						$rs     = $db->query($sql);
    						$config = $rs->fetch_assoc();
    
    						$header  = "From: ".$config['email']."\r\n";
    						$header .= "MIME-Version: 1.0\r\n";
    						$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    
    						$heading= "Project Completed";
    
    						$sql = "SELECT * FROM tbl_projects where id = '".$_POST["id"]."'";
    						$rs = mysql_query($sql);
    						$row_project = mysql_fetch_array($rs);
    
    						$sql = "SELECT * FROM tbl_users where `id`='".$row_project['uid']."'";
    						$rs = mysql_query($sql);
    						$row_user = mysql_fetch_array($rs);
    
    
    						$body="<table width=100% style='font-size: medium; padding: 1em; background-color:#FFFFFF; border-color:#8c9399; border-width:14px; border-style:solid;'>
    						<tr><td><font face=Arial, Helvetica, sans-serif size=6px>Welcome to ".$configrow['website_title'].",</font><br/><br/></td></tr>
    						<tr><td><font face=Arial, Helvetica, sans-serif size=4px>Pls Check your Revised Request Complated</font><br/><br/></td>
    						</td></tr>
    						<tr><td><font face=Arial, Helvetica, sans-serif size=4px>Regards, ".$configrow['website_title'].".
    						</td></tr></table>";
    
    						@mail($row_user['email'],$heading,$body,$header);
    
    						
    				    }	
    
    PHP:
     
    joshuaadams, Jul 5, 2012 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    What is the problem actually? can paste it here?

    If you're not seeing any error, please remove @ in your code.
     
    gapz101, Jul 5, 2012 IP
  3. KristianI

    KristianI Greenhorn

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    8
    #3
    Always check return values... From this you can not say that your email was sent or not.

    if(mail($row_user['email'], $heading, $body, $header)) {
    echo 'Mail sent';
    } else {
    echo 'Error, something went wrong while sending';
    }

    If you got an error, you should check your php configuration, some hosts disable this.
     
    KristianI, Jul 6, 2012 IP
  4. extraspecial

    extraspecial Member

    Messages:
    788
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    45
    #4
    Most of php mail ends up in spam therefore I recommend to use a SMTP service like SendGrid provides just google it, they give 200 emails per day for free!
     
    extraspecial, Jul 8, 2012 IP