Send function - cannot get send function to outside emails

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
jazz
Forum Newbie
Posts: 5
Joined: Thu Aug 09, 2007 12:53 pm

Send function - cannot get send function to outside emails

Post by jazz »

Hi,
I am using the php Send function to email clients, but my clients are not receiving the emails. I can use the function and email myself to our company email but if I email to other emails the email is never received. Any suggestions?

Thank you.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What PHP send function? And what code do you have already done. It is a lot harder to diagnose your problem when you give us nothing to diagnose with.
jazz
Forum Newbie
Posts: 5
Joined: Thu Aug 09, 2007 12:53 pm

OOPs wrong function name

Post by jazz »

Sorry, I meant the Mail function. I send mail using the php Mail function and it will not send emails outside of our domain.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Threre are many and various reasons: e.g. misconfigured mail server, SPF records, etc.
There are 10 types of people in this world, those who understand binary and those who don't
jazz
Forum Newbie
Posts: 5
Joined: Thu Aug 09, 2007 12:53 pm

Post by jazz »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This is the code.  It used to work.  I have made no changes to the code but our web server had many problems earlier this year.

Code: Select all

<?php session_start();  
	  require '../functions.php';  	

	  
//FLAG TO CHECK IF INVESTIGATOR HAS ALREADY BEEN INVITED
$bIfExists = false;
$aInvitedInvestigators = array();

//LOOP AND CHECK IF INVESTIGATOR HAS ALREADY BEEN INVITED
for( $i=1; $i<=$_POST["numinvestigators"]; $i++ )
{
	//INVITATION NUMBER IS A COMBINATION OF 'Email Address' + 'Project ID' + 'ClientID' MD5 HASH
	$rand = substr( md5( strtolower(trim($_POST["to$i"]))."-".$_POST["projectid"]."-".$_POST["clientid"]  ),0,8);
	$inviteNO = $ip."-".$rand;
	$query = "SELECT * FROM inviteprojects WHERE InviteNo LIKE '%".$inviteNO."%'";
	$result = execute_query( $query );
	if( mysql_num_rows( $result ) > 0 )
	{
		$bIfExists = true;
		$aInvitedInvestigators[] = "<b>".$i.".</b> ".$_POST["investname$i"].", <span style=\"color:#f00;\">".$_POST["to$i"]."</span>";
	}
}

//SHOW AN ERROR MESSAGE
if( $bIfExists ) 
{
	//GATHER POST ARRAY DATA
	$PostData = "";
	while( list($key,$val) = each($_POST)) {
	   $$key = $val;
	   $key  = trim($key);
	   $key  = stripslashes($key);
	   $key  = strip_tags($key);
	   $PostData .= "&".$key."=".urlencode($val);
	}
	?>
	<html>
	<head>
	<TITLE>Goodwyn IRB</TITLE>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<link href="../css/goodwyn.css" rel="stylesheet" type="text/css">
	</head>
	<?
	$sInvesitgatorList = implode("<BR>\n",$aInvitedInvestigators);
	print("<body><p>&nbsp;</p><center><p align=\"left\" style=\"padding:10px;width:70%;background-color:#F1DEDE;font-family:Verdana,Arial,Helvetica;font-size:11px;color:#000;border-width:2px;border-style:solid;border-color:#ff0000;\" ><strong>Error:</strong> Following investigators have already been invited for the project: <strong>".stripslashes($_REQUEST["projectname"])."</strong><br><br>".$sInvesitgatorList."<br><br><br><strong>Note:</strong> Please Try using different \"<em>Email Address</em>\"</p></center>");
	print("<center><p><a href=\"inviteinvest.php?".session_name()."=".session_id().$PostData."\" >BACK</a></p></center></body></html>");
	exit;
}


?>
<meta http-equiv="refresh" content="5;url=selectproject_fc.php?<?=session_name()?>=<?=session_id()?>">
<?php


//GET ADMINISTRATOR E-MAIL ADDRESS
$_SQL = "SELECT * FROM admin where ID=1";
$_RS = execute_query( $_SQL );
$_REC = mysql_fetch_array( $_RS );

//GET IP ADDRESS FOR INIVATION NUMBER
if(getenv("HTTP_CLIENT_IP")) { 
	$ip = getenv("HTTP_CLIENT_IP"); 
} elseif(getenv("HTTP_X_FORWARDED_FOR")) { 
	$ip = getenv("HTTP_X_FORWARDED_FOR"); 
} else { 
	$ip = getenv("REMOTE_ADDR"); 
}

//LOOP AND START SEND EMAIL TO EACH INVESTIGATOR
for( $i=1; $i<=$_POST["numinvestigators"]; $i++ )
{
	$rand = substr( md5( strtolower(trim($_POST["to$i"]))."-".$_POST["projectid"]."-".$_POST["clientid"] ),0,8);
	$inviteNO = $ip."-".$rand;
	$pname = stripslashes($_POST["projectname"]);
	$company = stripslashes($_POST["company"]);
	//$sdate = $_POST["sdate"];
	$to = $_POST["to$i"];
	$subject = stripslashes($_POST["subject"]);
	//$text = $_POST["body1"];
	//$headers .= "From: ".$_POST["from"]."\r\nBcc:".$_REC["email"]."\r\nContent-Type: text/html; charset=iso-8859-1\r\n";
	$headers .= "From: ".$_POST["from"]."\r\nBcc:ekelso@goodwynirb.com\r\nContent-Type: text/html; charset=iso-8859-1\r\n";
	//$headers .= "From: ".$_POST["from"]."\r\nBcc:ekelso@goodwynirb.com";

/*
$query = "Select * From inviteprojects Where ProjectID='".$_POST["projectid"]."' AND ClientID='".$_POST["clientid"]."'";
$rs = execute_query($query);
$record = mysql_fetch_array($rs);
$inviteNO = $record["InviteNo"];
*/

//CHECK IF INVESTIGATOR EMAIL EXISTS
$sql_query = "SELECT * FROM investigators WHERE LCASE(PublicEmail) LIKE '%".strtolower(trim($_POST["to$i"]))."%' OR LCASE(PrivateEmail) LIKE '%".strtolower(trim($_POST["to$i"]))."%'";
$_result = execute_query( $sql_query );
$_num_rows = mysql_num_rows( $_result );
if ( $_num_rows == 0 ) {
	$_link = "<a href=\"http://$HTTP_HOST/$DOCROOT/invest_reg.php\">Goodwyn IRB Submission Services</a>";
} else {
	$_link = "<a href=\"http://$HTTP_HOST/$DOCROOT/invest_login.php\">Goodwyn IRB Submission Services</a>";
}
//DEBUG :echo("<BR>".$_POST["to$i"]. "<BR>".$_num_rows."<BR>" );
/////////////////////////////////////////
$body =  "<p><strong>".trim($_POST["investname$i"])."</strong></p>";
$body .= "You have been invited to participate as a clinical investigator in the following research project:  <strong>".$pname."</strong>. The central IRB for this project is Goodwyn Institutional Review Board, Ltd. (Goodwyn IRB&reg;).  If your research site is eligible to use central IRB services, please visit http://www.goodwynirb.com and register as an investigator for this project.  
You will need the following Invitation Number <strong>".$inviteNO."</strong> to accept this invitation.<br>

<br>".$_link."<br><br>

If you have any questions or need assistance with this process, please call <strong>513-793-8900</strong>.";	  
$response = mail($to,$subject,$body,$headers);


//INSERT INVITATION TO TABLE
$query = "REPLACE Into inviteprojects Values('".$inviteNO."','','".trim($_POST["investname$i"])."','".$_POST["projectid"]."','".$_POST["clientid"]."','".date("Y-m-d")."','Not Accepted','','')";
execute_query($query);

$response = mail("tmahaney@goodwynirb.com",$subject.$_POST["to$i"],$body,$headers);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
jazz
Forum Newbie
Posts: 5
Joined: Thu Aug 09, 2007 12:53 pm

Post by jazz »

I am not sure what SPF records are. If it is the mail server, any suggestions on what I should look at? We use Mailenable and hos the mailon the same server as the web site. I did look at the php.ini file but did not see anything within the file that was incorrect (of course that doesn't mean that there isn't something that is wrong).

Thank you.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Do you receive any error emails from the domain you are trying to send emails to?
There are 10 types of people in this world, those who understand binary and those who don't
jazz
Forum Newbie
Posts: 5
Joined: Thu Aug 09, 2007 12:53 pm

Post by jazz »

No. I received no error messages. The only reason I knew it wasn't working is a client called and told me the emails he sent were not being delivered. This is a part of our site that is not used often. I tested myself and it will send to emails within our domain but not out of our domain. If I use my regular email client (not the web site), I can send outside of our domain.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

1. check out for messages in postmaster@your_domain_here
2. check your mail server config
3. check your logs (i.e. /log/mail.log Linux OS)
4. check your MX records for your domain and PTR records for the mail server IP
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try using Swiftmailer written by our very own d11wtq. It is a very good tool that offers a lot of useful information.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Everah wrote:Try using Swiftmailer written by our very own d11wtq. It is a very good tool that offers a lot of useful information.
If there is a problem at SMTP and related layers, it would not help ...
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply