Solved

php 5.2.4 mail only sends to same domain, not other email addresses

Posted on 2008-10-28
9
978 Views
Last Modified: 2013-12-18
php 5.2.4 mail only sends to email addresses in same domain, not other email addresses. It is a dedicated server but the hosting company has said they tested it and don't provide support for third party scripting.
<?php

   //Form input cleaning function

   function clean ($input, $maxLength)

   {

      $input = substr($input, 0, $maxLength);

	  $input = EscapeShellCmd($input);

	  return ($input);

   }//end function  

	

	

	$submit = $_POST['submit'];

   

	if(isset($submit))

	{

	   $contentOK = true;

		$completed = false;

		$firstName = clean($_POST["firstName"], 50);

		if($firstName == ""){ $contentOK = false;}

		

		$lastName = clean($_POST["lastName"], 50);

		if($lastName == ""){ $contentOK = false;}

		

		$company = clean($_POST["company"], 50);

		if($company == ""){ $contentOK = false;}

		

		$phone = clean($_POST["phone"], 20);

		if($phone == ""){ $contentOK = false;}

		

		$email= clean($_POST["useremail"], 40);

		if($email == ""){ $contentOK = false;}

		

		$question = clean($_POST["question"], 1000);

		

	   if( $contentOK == true)

	   {

	      //Form submission is validated - send email then redirect

         $registerTime = date("d/m/Y h:i a", mktime());

			

			//Send email to musician.com.au.

			

			//$emailTo = "test@otherdomain.com.au";

			$emailTo = "support@mydomain.com.au,email@test.com.au";

			//$emailTo = "email@test.com.au";

			

			mail($emailTo , "mydomain.com.au  - Contact Us.", 

"\r\n

The following person has made an enquiry at www.mydomain.com.au

---------------------------------------------------------------------\r\n

Name:                  $firstName $lastName

Company:               $company

Phone:                 $phone

Email:                 $email

Date:                  $registerTime

	

Enquiry:

 

$question 
 

---------------------------------------------------------------------

   

   This is an automatically generated email, please do not respond.",

   "From: webmaster@mydomain.com.au\r\n"

   ."Reply-To: $email\r\n"

   ."X-Mailer: PHP/" . phpversion())."\r\n";

	

	$completed = true;
 

	  }

	  else

	  {

	     $error = "<span style=\"color: red; font-weight: bold;\">*Please complete all mandatory fields.</span>";

	  }

	}

	

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta name="description" content="" />

<meta name="keywords" content="" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>my company | CONTACT US</title>

<!--[if !IE]> <-->

<script type="text/javascript" src="adxmenu/ADxMenu.js"></script>

<!--> <![endif]-->

<style type="text/css" media="screen, tv, projection">

	@import "adxmenu/MenuInd.css";

</style>

<!--[if lte IE 6]>

<style type="text/css" media="screen, tv, projection">

	@import "adxmenu/Menu4IEInd.css";

	body { behavior:url("adxmenu/ADxMenuInd.htc"); }

</style>

<![endif]-->

<!-- <script src="imageswap.js" type="text/javascript"></script>

<script language="JavaScript1.2" src="fw_menu.js" type="text/javascript"></script>

<style type="text/css"> -->

<!--

A:link    {color:#000000; text-decoration:none;}

A:visited {color:#000000; text-decoration:none;}

A:active  {color:#666666; text-decoration:none;}

A:hover   {color:#947E50; text-decoration:none;}

-->

</style>

<link href="wag_style.css" rel="stylesheet" type="text/css" />

<SCRIPT LANGUAGE="JavaScript" src="validation.js"></script>

</head>

<?

	$vPageName=basename($_SERVER['PHP_SELF']); 

?>

<body background="images/bg_lev2.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="900" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="bodytext">

  <tr>

    <td valign="top"><img src="images/logo_lev2.gif" width="900" height="126" /></td>

  </tr>

  

  <tr>

    <td background="images/line_bg.gif"><img src="images/spacer.gif" width="1" height="1" /><img src="images/line_bg.gif" width="1" height="5" /></td>

  </tr>

  <tr>

    <td><table width="100%" border="0" cellpadding="0" cellspacing="0">

      <tr>

        <td width="1%" valign="top" bgcolor="#023401"><table width="100%" border="0" cellspacing="0" cellpadding="0">

              <tr>

                <td align="center" valign="middle" class="nav"><div id="menu">

                    <ul id="menuList" class="adxm">

                      <li><a href="index.html">HOME</a>					  </li>

                      <li><a href="services.html">SERVICES</a></li>

                      <li><a href="about.html">ABOUT US</a></li>

                      <li><a href="contact.php">CONTACT US</a></li>

                    </ul>					  

					  </li>

				    </ul>

                </div>                </tr>

            </table></td>

        <td width="1%" rowspan="2"><img src="images/spacer.gif" width="1" height="5" /></td>

        <td rowspan="2" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">

          <tr>

            <td background="images/block_grey.gif"><img src="images/block_grey.gif" width="5" height="14" /></td>

          </tr>

          <tr>

            <td><table width="100%" border="0" cellspacing="0" cellpadding="15">

              <tr>

                <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">

                  <tr>

                    <td valign="top"><h1>CONTACT US </h1>

                      You can contact us via the details below or alternatively you may fill in the following form: -<br />

                      <br />

                      <table width="50%" border="0" cellspacing="0" cellpadding="5">

                        <tr>

                          <td width="50%" align="left" valign="top"><table width="100%" cellpadding="0" cellspacing="0">

                                <tr>

                                  <td width="33%" align="left"><strong>Mobile:</strong></td>

                                  <td></td>

                                </tr>

                              <tr>

                                  <td align="left" width="40"><strong>Phone:</strong></td>

                                  <td></td>

                                </tr>

                                <tr>

                                  <td align="left" width="40"><strong>Fax:</strong></td>

                                  <td></td>

                                </tr>

                            </table></td>

                          <td align="left" valign="top">&nbsp;</td>

                        </tr>

                      </table>

                      <br />

					  <table width="100%" border="0" cellpadding="2" cellspacing="0">

                            <tr>

                              <td><table width="100%" border="0" cellspacing="0" cellpadding="0">

                                        <tr>

                                          <td width="25%" valign="top">

										    <div align="center">

										      <?php

							 if($completed==true)

							 {

							 

							 ?>

										      </span>

										      <span class="bodytext">Thank you for your enquiry <strong><?php echo $firstName; ?></strong></span>

										      </p>

		                                    </div>

										    <p align="center" class="bodytext"> We will respond to your message shortly</p>

                <span class="boldtext">

                <div align="center">

                  <?php

							 }

							 else

							 {

								 if(isset($error))

								 {

								    echo $error;

								 }

								 

						?>

                  </div>

				  <table width="410" border="0" cellspacing="0" cellpadding="0">

                  <tr>

                    <td valign="top" class="bodycopy">

                      <form name="contact" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">

                        <table width="100%" border="0" cellspacing="0" cellpadding="1">

                          <tr>

                            <td class="bodytext" width="19%">First Name:</td>

                            <td class="bodytext" colspan="2">*

                                <input name="firstName" type="text" id="firstName2" size="25" value="<?php echo $firstName; ?>" />                            </td>

                          </tr>

                          <tr>

                            <td class="bodytext" width="19%">Last Name:</td>

                            <td class="bodytext" colspan="2">*

                                <input name="lastName" type="text" id="lastName" size="25" value="<?php echo $lastName; ?>" />                            </td>

                          </tr>

                          <tr>

                            <td class="bodycopy" width="19%"><p class="bodytext">Company:</p></td>

                            <td class="bodytext" colspan="2">*

                                <input name="company" type="text" id="email" size="40" value="<?php echo $company; ?>" />                            </td>

                          </tr>

                          <tr>

                            <td class="bodytext" width="19%">Phone:</td>

                            <td class="bodytext" colspan="2">*

                                <input name="phone" type="text" id="phone" size="25" value="<?php echo $phone; ?>" />                            </td>

                          </tr>

                          <tr>

                            <td class="bodytext" width="19%">Email:</td>

                            <td class="bodytext" colspan="2">*

                                <input name="useremail" type="text" id="useremail" size="25" value="<?php echo $email; ?>" />                            </td>

                          </tr>

                          <tr>

                            <td class="bodytext" colspan="3">Questions or areas of interest:</td>

                          </tr>

                          <tr>

                            <td class="bodysml" width="19%">&nbsp;</td>

                            <td class="boldtext" colspan="2">

                              <span class="bodytext">

                              <textarea name="question" id="question" cols="40" rows="5"><?php echo $question; ?></textarea>

                              </span></td>

                          </tr>

                          <tr>

                            <td class="bodysml" width="19%">&nbsp;</td>

                            <td class="bodysml" width="200"><div align="left" class="bodytext"><img src="images/1pix-yellow.gif" width="3" height="15">* mandatory fields </div></td>

                            <td class="bodysml" width="38"><div align="right">

                                <span class="bodytext">

                                <input type="submit" class="bodycopy" value="SEND" name="submit" onClick="return checkrequired(this)">

                                </span></div></td>

                          </tr>

                        </table>

                      </form>                      </td>

                  </tr>

                </table>

				  </td>

                                          <td width="25%" valign="top"><img src="" alt="Juliana" width="133" height="130" /></td>

                                      </tr>

                                      </table>

                              </td>

                            </tr>

                          </table></td>

                  </tr>

                </table></td>

              </tr>

            </table></td>

          </tr>

          <tr>

            <td valign="top" background="images/block_grey.gif">&nbsp;</td>

          </tr>

        </table></td>

      </tr>

      <tr>

        <td valign="middle" bgcolor="#023401"><img src="images/left_col.gif" width="161" height="3" align="bottom" /></td>

      </tr>

      <tr>

        <td colspan="3" valign="bottom" background="images/line_bg.gif"><img src="images/line_bg.gif" width="1" height="5" /></td>

      </tr>

      <tr>

        <td colspan="3" align="center" valign="bottom" class="credits"><img src="images/spacer.gif" width="1" height="5" />website design <a href="http://www.otherdomain.com.au" target="_blank" class="credits">otherdomain.com.au</a> </td>

      </tr>

    </table></td>

  </tr>

</table> <?php } ?>

</body>

</html>

Open in new window

0
Comment
Question by:ditterz
  • 4
  • 4
9 Comments
 
LVL 9

Expert Comment

by:mgonullu
ID: 22819765
Is the SMTP server configured in a right way in the php.ini configuration?
Maybe that SMTP requires authentication when sending outside the domain
The last reason is that it could be a port problem
0
 
LVL 17

Assisted Solution

by:psimation
psimation earned 50 total points
ID: 22820139
rather use a proper smtp mailer class.

http://sourceforge.net/projects/phpmailer/
0
 

Author Comment

by:ditterz
ID: 22820465
The domain is hosted on a different server and the name servers point to the web server, but our email accounts are configured from the web server and work OK. Do we have to change something in the DNS records?

The phpinfo.php shows the info below: -
SMTP localhost localhost
smtp_port 25 25
Path to sendmail  /usr/sbin/sendmail -t -i  
0
 
LVL 17

Assisted Solution

by:psimation
psimation earned 50 total points
ID: 22820508
php's mail() function is VERY basic, and simply passes your parameters to sendmail.

So, what usually happens is that the resulting e-mail gets sent with the default sendmail configuration on that server, AND will most likely process the envelope to come from the "apache" or "php" user depending on what user the apache/php processes runs as. If you use the -f flag to force a "From" in your mail, the envelope gets stamped with an X-Authentication warning - and lots of mailservers will reject the mail as spam based just on that.

Hence my suggestion to use a proper smtp mailer class, since that allows you to send the email in the same way as you would send it from Outlook or whatever email client you normally use.

This means that you pass proper authentication parameters to the smtp server who then properly writes the message envelope according to the username/password you supply to it, and as such, a much higher percentage of recipient mailservers will accept your e-mails and deliver them.
0
Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

 
LVL 17

Expert Comment

by:psimation
ID: 22820537
Here is a very simple example of the mailer class as per the link I sent you, simply download the two class files and put them in the same folder as this file, then add this code:
$messagebody = "Add your message here in text or HTML - you can even have text only message body and html only mesage body";

$toaddress = "whatever@wherever.com";

$toaddress2 = "whatever2@wherever.com";

$toaddress3 = "whatever3@wherever.com";
 

require("class.phpmailer.php");
 

$mail = new PHPMailer();

$mail->IsSMTP();                                      

$mail->Host = "smtp.yoursmtpserver.dom";  

$mail->SMTPAuth = true; 

$mail->Username = "username";

$mail->Password = "password";

$mail->From = "you@youraddress.dom";

$mail->FromName = "You";

$mail->AddAddress($toaddress);

$mail->AddAddress($toaddress2);

$mail->AddAddress($toaddress3);

$mail->WordWrap = 50;                                 

$mail->IsHTML(true);                                  

$mail->Subject = "subject";

$mail->Body    = $messagebody;

$mail->Send();

Open in new window

0
 

Author Comment

by:ditterz
ID: 22827333
The code (after adding my configuration details) when uploaded didn't do anything beyond causing the following error in the web server's error log in Plesk: -

[Tue Oct 28 23:43:23 2008] [error] [client 121.212.130.198] PHP Warning: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]: unable to connect to mail.bigpond.com:25 (Connection timed out) in /var/www/vhosts/mydomain.com.au/httpdocs/mailtest/class.smtp.php on line 122

I use mail.bigpond.com in outlook as the outgoing server on port 25. I pinged it and got the result below: -

Pinging mail.bigpond.com [61.9.189.249] with 32 bytes of data:
Reply from 61.9.189.249: bytes=32 time=18ms TTL=247
0
 

Accepted Solution

by:
ditterz earned 0 total points
ID: 22828280
I used the example test_sendmail.php file that came with phpmailer, and this worked. I then queried our hosting company who ran a test on the basic php binary sendmail function, which hadn't been working but now magically works. I don't know what they did (nothing! they say) but it's working now.

Thanks for your help. At least I have learnt how to use phpmailer.
0
 
LVL 17

Expert Comment

by:psimation
ID: 22828796
ditterz, glad you found a solution - but I think it's worth mentioning again - using php mail() is NOT a good idea if you want to ensure reliable e-mail comms with your clients. You are 99% there, you say you got the test to work with phpmailer - I would advise you to push for the extra 1% and get phpmailer to work - in the long run you will be better off...
0
 

Author Comment

by:ditterz
ID: 22836681
This system uses Mail.php from Pear. My assumption that it was using the basic php mail() was incorrect. Whatever problem that was fixed by the web host allowed our basic php mail() tests to work as well as the Pear Mail and the phpmailer. I tested with all and now they all work. The hosting company also said that the X-Authentication warning flag was not set in this case. But there must have been a permissions problem they fixed. Their initial test was done at the command line and they said nothing was wrong. Then I asked them for a test that I could also run and I think that's when they found the problem. Magically it worked after that. There are some email accounts that are still not receiving the e-mails, but they could have spam filters blocking them at their webserver level, so we will investigate that, but our own tests have been successful. I am assuming the pear Mail.php is up to the job as it has an smpt.php option.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
This article discusses four methods for overlaying images in a container on a web page
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now