hi

I can't send emails through a PHP script using
Code:
mail();
It's really more of a server issue as from close inspection the PHP code is fine.

Code:
<?php

	/*
	DONT FORGET TO DELETE THIS SCRIPT WHEN FINISHED!

	Usage: http://mydomain.org/testMail.php?email=myaccount@yahoo.com&send=true
	*/

	ini_set( 'display_errors', 1 );
	error_reporting( E_ALL );
	
	$from = 'admin@mydomain.org';
	
	$server = array( 
		'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR', 'SERVER_PORT',
 		'SERVER_ADMIN', 'SERVER_SIGNATURE', 'SERVER_SOFTWARE', 
		'REMOTE_ADDR', 'DOCUMENT_ROOT', 'REQUEST_URI', 
		'SCRIPT_NAME', 'SCRIPT_FILENAME',
	);
	
	$to      = ( isset( $_GET['email'] ) ? $_GET['email'] : FALSE );
	$subject = 'Mail Test Successful for ' . $_SERVER['HTTP_HOST'];
	$message = 'hola, FreeBSD server is sending mail!';
	
	if ( ! $to )
	{
		echo '<strong>Set $_GET[\'email\'].</strong>';
		exit;
	};
	
	foreach ( $server as $s )
	{
		$message .= sprintf( '%s: %s', $s, $_SERVER[$s] ) . PHP_EOL;
	};
	
	$headers = 'From: ' . $from . PHP_EOL 
		 . 'Reply-To: ' . $from . PHP_EOL 
		 . 'X-Mailer: PHP/' . phpversion(); 
	
	if ( isset( $_GET['send'] ) && $_GET['send'] === 'true' )
	{					
		$success = mail( $to, $subject, $message, $headers );
	}
	else
	{
		echo '<strong>Set &quot;<a href="./?email=' . $to . '&send=true">'
		 . './?email=' . $to . '&send=true</a>&quot; to send a test e-mail.</strong>';
	};
	
	if ( isset( $success ) )
	{	
		echo 'E-mail sent to: ' . $to;
		echo '<br />';
		echo 'Successful mail?: <strong ' . ( $success ? 'style="color:green;">YES' : 'style="color:red;">NO' ) . '</strong>';
	}
	else
	{
		echo '<br />';
		echo 'E-mail set as: '.$to;
	};
	
	echo '<hr />';	
	echo '<style>	* { font-family: Helvetica, Arial, sans-serif;  } th { text-align: left; } td { padding: 3px 5px; }	</style>';
	echo '<table>';	
	
	foreach ( $server as $s )
	{
		echo '<tr><th>$_SERVER[\'' . $s . '\']</th><td>' . $_SERVER[$s] . '</td></tr>';
	};
	
	echo '</table>';
	
	if ( isset( $success ) )
	{
		echo '<!--'; 
		var_dump( $success );		
		echo '-->';
	};
?>
My server OS is FreeBSD and I have *AMP installed. Here's a snapshot of php.ini


Code:
sendmail_path	/usr/sbin/sendmail	/usr/sbin/sendmail
SMTP	localhost	localhost
smtp_port 25     25
My MTA is Sendmail. Sendmail works fine on my server and from the command line I can send and receive emails to external/internal accounts from the shell. I have MX records in DNS for admin@mydomain.org.

If I tail my log file :
Code:
$ tail -f /var/log/maillog
looking at a sample:
Code:
May  6 13:16:28 web sm-mta[13578]: r46HGQ4f013576: to=<myaccount@yahoo.com>, ctladdr=<admin@mydomain.org> (1004/1004), delay=00:00:02, xdelay=00:00:01, mailer=esmtp, pri=30403, relay=mta7.am0.yahoodns.net. [66.196.118.34], dsn=2.0.0, stat=Sent (ok dirdel)


May  6 14:00:03 web sendmail[13671]: r46I03Yp013671: from=www, size=666, class=0, nrcpts=0, msgid=<201305061800.r46I03Yp013671@host.mydomain.org>, relay=www@localhost
The first message would indicate a successful transfer. It's an email from user 'admin' on my server (shell) out to my Yahoo account. The second entry is the result of the PHP script (again sent from my server); as you can see the two are not the same.

Forgetting the first entry for a moment. Essentially I'm trying to send a message from my server to Yahoo only using PHPs mail() function.

From the second message; I'm told that the relay option looks faulty: http://forums.freebsd.org/showthread...216#post219216


Can you help? I have root access to the VPS if you need more information.