Jump to content

Recommended Posts

Hi:

My Website host has installed suexec on Apache and this has stopped my regular mail() function from sending out automatic confirmation emails when a user submits a form for membership. I am not sure how to change my script to make this work again...

 

Any help would be greatly appreciated.

 

Thanks.

:'(

Link to comment
https://forums.phpfreaks.com/topic/53113-php-mail-function-stopped-working/
Share on other sites

I did check with my host, and this is the answer I got from them:

'Hi,

 

Suexec is enabled on the server, So you can send email via php, You want to provide your user id in PHP coding.

 

 

Regards,

Win Web Hosting Support

We Believe in the Power of Small Businesses'

 

I am not sure when they say ' You want to provide your user id in PHP coding'...?????

 

Here is the code:

 

<?
include("../conf.php");
if (!$_POST['submit'])
{
?>
<html>
<head>
<basefont face="Verdana">
</head>
<body bgcolor="white" topmargin="20">
<table align="center" cellspacing="1" cellpadding="1" bgcolor="#8CCAD0" border="1" bordercolor="#666666">
<form action="<? echo $PHP_SELF; ?>" method="POST">
<tr>
        <td colspan="4" align="center" valign="top"><b><font size="-1">Application for Membership</font></b></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">Last Name:</font><font color="#FF0000" size="-1"> *</font></b></td>
        <td colspan="2"><input size="53" maxlength="50" type="text" name="LName"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">First Name:</font><font color="#FF0000" size="-1"> *</font></b></td>
        <td colspan="2"><input size="53" maxlength="50" type="text" name="FName"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">Address:</font><font color="#FF0000" size="-1"> *</font></b></td>
        <td colspan="2"><input size="53" maxlength="50" type="text" name="address"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">City:</font><font color="#FF0000" size="-1"> *</font>
        <td colspan="2"><input size="20" maxlength="20" type="text" name="city"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">Country:</font><font color="#FF0000" size="-1"> *</font>
        <td colspan="2"><input size="20" maxlength="20" type="text" name="country"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">Home Phone:</font><font color="#FF0000" size="-1"> *</font></td>
        <td colspan="2"><input size="13" maxlength="13" type="text" name="homephone"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">Cell Phone:</font><font color="#FF0000" size="-2"></b> (Optional)</font></td>
        <td colspan="2"><input size="13" maxlength="13" type="text" name="cellphone"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">User ID:</font><font color="#FF0000" size="-1"> *</font></td>
        <td colspan="2"><input size="10" maxlength="10" type="text" name="userid"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">Your Email:</font><font color="#FF0000" size="-1"> *</font></td>
        <td colspan="2"><input size="50" maxlength="50" type="text" name="email"></td>
</tr>
<tr>
        <td valign="top"><b><font size="-1">Password:</font><font color="#FF0000" size="-1"> *</font></td>
        <td colspan="2"><input size="10" maxlength="10" type="password" name="pwd1"></td>
</tr-->
<tr>
        <td valign="top"><b><font size="-1">Retype Password:</font><font color="#FF0000" size="-1"> *</font></td>
        <td colspan="2"><input size="10" maxlength="10" type="password" name="pwd2"></td>
</tr>
<tr>
        <td><font color="#FF0000" size="-2">* Required for Processing!</font></td><td colspan="2"><input type="Submit" name="submit" value="Submit">
        <input type="Button" name="cancel" value="Cancel" onClick="Javascript:location = 'xxxx.htm'"></td>
</tr>
</form>
</table>
<?php
} else {
$LName = $_POST['LName'];
$FName = $_POST['FName'];
$address = $_POST['address'];
$city = $_POST['city'];
$country = $_POST['country'];
$homephone = $_POST['homephone'];
$cellphone = $_POST['cellphone'];
$userid = $_POST['userid'];
$email = $_POST['email'];
$pwd1 = $_POST['pwd1'];
$pwd2 = $_POST['pwd2'];
  if (empty($userid)) {
      $error = true;
      $errormessage .= "<li><b>Sorry.  You did not enter a User ID.</b><br>\n";
      } else {
             $sql = "select * from tablename where Userid = '$loginid'";
             $result = mysql_query($sql) or die ("Error in query: $query. " . mysql_error());
             $totalRowsLogin = mysql_num_rows($result);
             if ($totalRowsLogin > 0) {
                 $error = true;
                 $errormessage .= "<li><b>Sorry.  That User ID has been taken already.</b><br>\n";
             }
  }
  if ((empty($LName)) || (empty($FName))) {
      $error = true;
      $errormessage .= "<li><b>Sorry.  We need your name only for addressing you properly.</b><br>\n";
      }
  if (empty($address)) {
      $error = true;
      $errormessage .= "<li><b>Sorry.  You did not enter an address.</b><br>\n";
      }
  if (empty($city)) {
      $error = true;
      $errormessage .= "<li><b>Sorry.  You did not enter a city.</b><br>\n";
      }
  if (empty($country)) {
      $error = true;
      $errormessage .= "<li><b>Sorry.  You did not enter a country.</b><br>\n";
      }
  if (empty($homephone)) {
      $error = true;
      $errormessage .= "<li><b>Sorry.  You did not enter your homephone.</b><br>\n";
      }
  if (empty($pwd1)) {
      $error = true;
      $errormessage .= "<li><b>Sorry.  Empty Passwords not allowed.</b><br>\n";
      }
  if ($pwd1 != $pwd2) {
      $error = true;
      $errormessage .= "<li><b>Sorry.  Passwords do not match.</b><br>\n";
      }
  if ($error) {
?>
        <table width='100%'><tr bgcolor='red'><td colspan="3" align="center"><strong><font size="-2" face="Verdana, Arial, Helvetica, sans-serif" color="white">Try Again</font></strong></font></td></tr>
        <tr>
        <td width="175"><font face='Verdana, Arial, Helvetica, sans-serif' color='#000000' size='-2'> </font></td>
	<td>
        <font color='black' size='-2' face='Geneva, Arial, Helvetica, sans-serif'><? echo $errormessage; ?>
<br>          <a onMouseOver="window.status='';return true" href="javascript:history.go(-1)">Click Here</a> to try again</font></td>
        <td width="175"><font face='Verdana, Arial, Helvetica, sans-serif' color='#000000' size='-2'> </font></td>
	</tr>
	<tr bgcolor='red'><td colspan="3"><font face='Verdana, Arial, Helvetica, sans-serif' color='#000000' size='-2'> </font></td></tr></table>
<?
exit;
  } else {
        $query = "INSERT INTO tablename(LName,FName,address,city,country,homephone,cellphone,email,UserID,AccessLevel,pwd) VALUES('$LName', '$FName', '$address','$city','$country','$homephone','$cellphone','$email', '$userid', 2, '$pwd')";
        $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
        $wmmail = 'morgan54@excite.com';
        $message = 'The following person applied for membership.\n'
            .'First Name: '.$FName.'\n'
            .'Last Name: '.$LName.'\n'
            .'E-mail: '.$email.'\n\n\n'
            .'A confirmation email was sent to '.$FName.'\n\n- Administrator';
        mail($wmmail, 'Application for Membership', $message,'From:$email');

        $app_message = 'Thank you '.$FName.' for applying for a membership!\n\n\nPlease save this message for future reference.\n\n\nOnce your application is approved, you will receive confirmation.\n\n\nHere is what you submitted to us:\n\n'
            			.'First Name: '.$FName.'\n'
            			.'Last Name: '.$LName.'\n'
                        .'Address: '.$address.'\n'
                        .'City: '.$city.'\n'
                        .'Country: '.$country.'\n'
                        .'Home Phone: '.$homephone.'\n'
                        .'Cell Phone: '.$cellphone.'\n'
            			.'E-mail: '.$email.'\n'
                        .'Your ID: '.$userid.'\n'
                        .'Your Password: '.$pwd.'\n';
        mail($email,'Received application',$app_message,'From:morgan54@excite.com');
        echo "<p align='center' valign='center'><font color='darkblue' size=2>Your ID was created and a confirmation email was sent to ".$email." ! <p align='center' valign='center'>Once your ID is activated, you will receive an email.</font></P>";
}
}
?>
</body>
</html>

you could try this

 

Note its untested

 

function mymail($to,$subject,$message,$headers)
{

  // set as global variable
  global $GLOBAL;
  
  // get From address
  if ( preg_match("/From:.*?[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+.*/", $headers, $froms) ) {
      preg_match("/[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+/", $froms[0], $fromarr);
      $from = $fromarr[0];
  }

  // Open an SMTP connection
  $cp = fsockopen ($GLOBAL["SMTP_SERVER"], $GLOBAL["SMTP_PORT"], &$errno, &$errstr, 1);
  if (!$cp)
   return "Failed to even make a connection";
  $res=fgets($cp,256);
  if(substr($res,0,3) != "220") return "Failed to connect";

  // Say hello...
  fputs($cp, "HELO ".$GLOBAL["SMTP_SERVER"]."\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "Failed to Introduce";
  
  // perform authentication
  fputs($cp, "auth login\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "334") return "Failed to Initiate Authentication";
  
  fputs($cp, base64_encode($GLOBAL["SMTP_USERNAME"])."\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "334") return "Failed to Provide Username for Authentication";
  
  fputs($cp, base64_encode($GLOBAL["SMTP_PASSWORD"])."\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "235") return "Failed to Authenticate";

  // Mail from...
  fputs($cp, "MAIL FROM: <$from>\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "MAIL FROM failed";

  // Rcpt to...
  fputs($cp, "RCPT TO: <$to>\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "RCPT TO failed";

  // Data...
  fputs($cp, "DATA\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "354") return "DATA failed";

  // Send To:, From:, Subject:, other headers, blank line, message, and finish
  // with a period on its own line (for end of message)
  fputs($cp, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "Message Body Failed";

  // ...And time to quit...
  fputs($cp,"QUIT\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "221") return "QUIT failed";

  return true;
}

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.