Jump to content

[SOLVED] Php mail - Can't figure out why, please help !


Recommended Posts

Hi all,

I have list of users that i need to send newstler to everyday, but for some reason my newstler always go to spam folder instead of the inbox. I want it send to the Inbox. I try to finger out for weeks but with my limit knowlege i coundn't finger out why. Can someone help me out or point me to the right direction.

Thanks in advance.

 

This is the code I use:

<style type="text/css">
</style>
<table border="0" align="center" cellpadding="5" cellspacing="2" width="100%" background="images/bg08.jpg">
<tr><td>
<table>
<tr><td width=93><table id="Table_01" width="93"  border="0" cellpadding="0" cellspacing="0">
                    <tr>
   <td><img src="images/links3_01.jpg" width="93" height="25" alt="" ></td>
                    </tr>
                <tr>
         <td><a href=mail.php?page=subjects><img src="images/links3_02.jpg" width="93" height="71" alt="" border="0" title="MailSubjects"></a></td>
                    </tr>
                    <tr>
                      <td><a href=mail.php><img src="images/links3_03.jpg" width="93" height="71" alt="" border=0 title="Sendmail"></a></td>
                    </tr>
                    <tr>
                      <td><a href=mail.php?page=news><img src="images/links3_04.jpg" width="93" height="74" alt="" border=0 title="SendNewsletter"></a></td>
                    </tr>
                    <tr>
                   
                </table></td><td width=793>
<table width="98%" class="border2" align="center">
  <tr bgcolor="#CCCCCC" class=txt_users> 
    <td height="27" colspan="2">Send an email to an user or all users</td>
  </tr>
<?php 
   $cansend = $_POST["cansend"];
   $users=$_POST["cboUsers"];
   
$sqlsite="select * from admin_settings where set_id=1";
$sqlsiteqry=mysql_query($sqlsite);
$sqlsitefetch=mysql_fetch_array($sqlsiteqry);
$site=$sqlsitefetch['set_value'];   
   
   //Fetching mail header image
$queryheader="select * from admin_settings where set_id = 61";
$tableheader=mysql_query($queryheader);
$rowheader=mysql_fetch_array($tableheader);
$mailheader = $site."/".$rowheader['set_value'];

//Fetching mail footer image
$queryfooter="select * from admin_settings where set_id = 62";
$tablefooter=mysql_query($queryfooter);
$rowfooter=mysql_fetch_array($tablefooter);
$mailfooter = $site."/".$rowfooter['set_value'];
   
if (($cansend==1) && ($users[0]!="All Users"))
  {    
        $qst_date=date("Y-m-d");
		$status="notification";
        $adminidres=mysql_query("select * from user_registration where user_name='admin'");
		$adminid=mysql_fetch_array($adminidres);
        $from_id=$adminid['user_id'];
		$to=$_POST['cboUsers'];
		$users=$_POST['cboUsers'];
		$mailfrom = $_POST["txtFrom"];
		$mailsubject = $_POST['txtSubject'];
		$mailbody= $_POST["txtMessage"];

		$mailtop="<table width=700 style=\"border-left:1px solid #CCCCCC;border-top:1px solid #CCCCCC; border-right:1px solid #cccccc; border-bottom:1px solid #cccccc\"><tr><td><img src='<imgh>'></td></tr><tr><td>";
		$mailbottom="</td></tr><tr><td><img src='<imgf>'></td></tr></table>";
		$mailtop=str_replace("<imgh>" , $mailheader , $mailtop);
            $mailbottom=str_replace("<imgf>" , $mailfooter , $mailbottom);
		$mailbody1=$mailtop."<tr><td>".$mailbody."</td></tr>".$mailbottom;



		foreach($users as $mailTo) {
		$userres=mysql_query("select * from user_registration where email='$mailTo'");
		$userqry=mysql_fetch_array($userres);
		$to_id=$userqry[user_id];
            $ins_sql="insert into ask_question(from_id,date,question,answer,to_id,status)             values('$from_id','$qst_date','$mailbody','$mailsubject','$to_id','$status')";
        $ins_qry=mysql_query($ins_sql);

		$headers  = "MIME-Version: 1.0\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1\n";
		$headers .= "From: ". $mailfrom."\n";
		$mail=mail($mailTo,$mailsubject,$mailbody1,$headers);

  }
          		if($mail)
			{
	        	$mailstatus = "Mail Send Successfully to the Selected users";
			}
			else
				$mailstatus =  "Problem in sending your Email...";
			}
	else if(($cansend==1) && ($users[0]=="All Users"))
	{   
	    $qst_date=date("Y-m-d");
		$status="notification";
	    $adminidres=mysql_query("select * from user_registration where user_name='admin'");
		$adminid=mysql_fetch_array($adminidres);
		$from_id=$adminid[user_id];
		$alres=mysql_query("select * from user_registration where verified='yes'");
		while($alrow=mysql_fetch_array($alres))
		{
		$to_id=$alrow['user_id'];
		$ins_row=mysql_query($ins_sql);
		$mailTo=$alrow['email'];
		$mailfrom = $_POST["txtFrom"];
		$mailsubject = $_POST['txtSubject'];
		$mailbody= $_POST["txtMessage"];

		$mailtop="<table width=700 style=\"border-left:1px solid #CCCCCC;border-top:1px solid #CCCCCC; border-right:1px solid #cccccc; border-bottom:1px solid #cccccc\"><tr><td><img src='<imgh>'></td></tr><tr><td>";
		$mailbottom="</td></tr><tr><td><img src='<imgf>'></td></tr></table>";
		$mailtop=str_replace("<imgh>" , $mailheader , $mailtop);
            $mailbottom=str_replace("<imgf>" , $mailfooter , $mailbottom);
		$mailbody1=$mailtop."<tr><td>".$mailbody."</td></tr>".$mailbottom;

		$ins_sql="insert into ask_question(from_id,date,question,answer,to_id,status) values('$from_id','$qst_date','$mailbody','$mailsubject','$to_id','$status')";
		$ins_qry=mysql_query($ins_sql);

		$headers  = "MIME-Version: 1.0\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1\n";
		$headers .= "From: ". $mailfrom."\n";

            $mail=mail($mailTo,$mailsubject,$mailbody1,$headers);
	    }
		    if($mail)
			{  
			    $mailstatus = "Mail Send Successfully to all users";	
			}
			else
			{
				$mailstatus =  "Problem in sending your Email...";
			}
		}

?>
              <?
                if ($mailstatus!="")
	{
                echo "<tr bgcolor=#eeeee1><td colspan=2 align=center><font color=#FF0000>".$mailstatus."</font></tr>";
                }
      ?>
              <tr>
<td valign="top" colspan=2><b></tr>
<form name=form1 action="<?php $_SERVER['PHP_SELF']; ?>" method=post>
<tr bgcolor="#eeeee1">
              <td width="50%">From 
              <td width="50%">
<?php
$frm_res=mysql_query("select * from mail_subjects");
$frm_row=mysql_fetch_array($frm_res);
?>
<input type="text" name="txtFrom" value="<?=$frm_row['mailfrom']; ?>" class="txt">
</td></tr>

<tr bgcolor="#eeeee1">
              <td>Subject
<td>
<input type="text" class="txt" name="txtSubject">
</td>
</tr>
<tr bgcolor="#eeeee1">
              <td valign=top>Message
<td><textarea name=txtMessage rows=5 cols=25></textarea>
<tr bgcolor="#eeeee1">
              <td>Send this Email to 
<td><select name="cboUsers[]" multiple><option value="All Users" selected="selected">All Users</option>
        <?php 
  $sql="select email from user_registration order by email";
   $result=mysql_query($sql);

	if(mysql_num_rows($result)<=0)
	{
		$error="No users";
	}
	else if(mysql_num_rows($result)>0)
	{
 		while ($row=mysql_fetch_array($result))
		{
	       	echo "<option value=". $row[0].">".$row[0]."</option>";
		}
	}
	?>

</select></td>
</tr>
<tr bgcolor="#eeeee1">
              <td height="28" colspan=2 align=center>
<input type=submit Value=" Send " class="button" onclick="return val();"></td></tr>
<input type=hidden name=cansend value=0>
</form>
</table></td></tr></table></td></tr></table>
<script language="javascript">
function val()
{
if(form1.txtFrom.value=="")
{
	alert("Please Enter the From Mail ID");
	form1.txtFrom.focus();
	return false;
}
if(form1.txtFrom.value !="")
{
	mailstr = form1.txtFrom.value;
	a = mailstr.indexOf(".");
	b = mailstr.indexOf("@");
	c = mailstr.indexOf(" ");
	d = mailstr.lastIndexOf(".");
	e = mailstr.length
	if( (a == -1) || (b == -1) || (c != -1) || (d < b) || ( d == e - 1) || (b+1 == a) )
	{
		alert("Enter the Valid E-Mail");
		form1.txtFrom.focus();
		return false;
	}
}	
if(form1.txtSubject.value=="")
{
	alert("Please Enter the Mail Subject");
	form1.txtSubject.focus();
	return false;
}
if(form1.txtMessage.value=="")
{
	alert("Please Enter the Message");
	form1.txtMessage.focus();
	return false;
}
form1.cansend.value=1;
return true;
}
</script>

I had this problem and had to correct the hosting company email server my self,

if the dns of the host is incorrectly configured it will never go to the inbox.

 

because mail is being sent, you no it not your code, It the host end that sending the,

emails.

 

basically if a host hasn't got a email server set up correctly, and the ip and domain name are

not unique, to that email server, you as a user, with php get all email sent to the spam box.

 

a lot off users say that there a email wrapper/headers that over comes this, but it not true it a myth.

 

no php header going to re design a host's email server.

 

would off said there on a ban list, but i no it the server setup off the host.

this is the only way i no to get around it by using your current

isp provider not your hoster.

 

1. you need to get all the info from your current broadband provider to send mail.

 

2. fill in all the provided info username/password in the form.

 

3. the code cheeks that all email elements are sent.

 

the only other way is to contact the host you use now and wait for a reply,

i no it annoying.

 

try Google if others having the same problem with the host your using now in Google, your be surprised.

 

try good luck.

sorry.

<?php
//new function

$to = "[email protected]";
$nameto = "redarrow";
$from = $to;
$namefrom = "redarrow";
$subject = "Hello World Again!";
$message = "World, Hello!";
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>

<?php

/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "smtp.blueyonder.co.uk";
$port = "25";
$timeout = "30";
$username = "your username from isp provider";
$password = "your password from isp provider";
$localhost = "localhost";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */

//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}

//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
}
?>

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.