Jump to content

Php mail not sending mail


tomfmason

Recommended Posts

I am using a script to send a users registration information.

Here is the script. Please look at it and tell me if the reason it is not sending is because of my coding. If not then it is Mercury mail

[code]} else {
    $userid = mysql_insert_id();
    $subject = "Your Membership at owpt.biz";
    $message = "Dear $first_name $last_name,
    You are now registered at our website, http://www.owpt.biz!
   
    To activate your membership, please login here: http://www.owpt.biz/home/index.php
   
    Once you activate your membership, you will be able to login with the following information:
    Username: $username
    Password: $random_password
    Please keep this username and password in a location that is easily accessible by you.
   
    Thanks!
    WebMaster, Owpt.biz
   
    This is an automated response, please do not reply!";
   
    mail($email_address, $subject, $message, "From: webmaster<webmaster@owpt.biz>\nX-Mailer: PHP/" . phpversion());
    echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
}
?>[/code]
Link to comment
Share on other sites

look at the code order ok then your see ok good luck clue $to


Another example of sending a utf-8 HTML mail:

$to = 'bob@barnyard.com';
$subject = 'Wakeup bob!';
$message = '<b>yo</b>, whassup?';
$headers = "From: server@barnyard.com\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";

// Send
mail($to, $subject, $message, $headers);
Link to comment
Share on other sites

ok at first I thought I was just stupid and forgot to enter the $to information.

I have tried it just like you said and no success. I am using Mercury Mail as my mail server, not sure if this has anything to do with it or not.

Here is one that is like your example.

[code]    $to = '$email_address';
    $subject = 'Your Membership at owpt.biz';
    $message = 'Dear $first_name $last_name,
    You are now registered at our website, http://www.owpt.biz!
   
    To activate your membership, please login here: http://www.owpt.biz/home/index.php
   
    Once you activate your membership, you will be able to login with the following information:
    Username: $username
    Password: $random_password
    Please keep this username and password in a location that is easily accessible by you.
   
    Thanks!
    WebMaster, Owpt.biz
   
    This is an automated response, please do not reply!';
    $headers = "From: noreply@owpt.biz\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";
    mail($to, $subject, $message, $headers);
[/code]

And here is another one that I have tried

[code]    $userid = mysql_insert_id();
    $to = "$email_address";
    $subject = "Your Membership at owpt.biz";
    $message = "Dear $first_name $last_name,
    You are now registered at our website, http://www.owpt.biz!
   
    To activate your membership, please login here: http://www.owpt.biz/home/index.php
   
    Once you activate your membership, you will be able to login with the following information:
    Username: $username
    Password: $random_password
    Please keep this username and password in a location that is easily accessible by you.
   
    Thanks!
    WebMaster, Owpt.biz
   
    This is an automated response, please do not reply!";
   
    mail($to, $subject, $message, "From: Noreply<noreply@owpt.biz>\nX-Mailer: PHP/" . phpversion());
[/code]

Link to comment
Share on other sites

ok now nether of those are working. So now I am thinking that there may be something wrong with the way that I am calling the information to be mailed. So I will post a copy of the entire script

[code]<?php
include 'db.php';
$first_name = $_POST['first_name'];
$lastname_name = $_POST['last_name'];
$username = $_POST['username'];
$email_address = $_POST['email'];

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$username = stripslashes($username);
$email_address = stripslashes($email);

# Any errors in the posted fields? Lets check...
if((!$first_name) || (!$last_name) || (!$email) || (!$username)){
echo 'You did not submit the following required information! <br/>';
if(!$first_name){
echo '<font id=UserNameRed />First name <font id=UserPanelText />is a required field. Please enter it below. <br/>';
}
if(!$last_name){
echo '<font id=UserNameRed />Last name <font id=UserPanelText />is a required field. Please enter it below. <br/>';
}
if(!$email){
echo '<font id=UserNameRed />Email address <font id=UserPanelText />is a required field. Please enter it below. <br/>';
}
if(!$username){
echo '<font id=UserNameRed />Username <font id=UserPanelText />is a required field. Please enter it below. <br/>';
}
include("../join.php");
exit();
}

$sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if(($email_check > 0) || ($username_check > 0)){
echo 'Please fix the following errors: <br/>';
if($email_check > 0){
echo '<strong>Your email address has already been used by another member in our database. Please use a different Email address!<br/>';
unset($email);
}
if($username_check > 0){
echo 'The username you have selected has already been used by another member in our database. Please choose a different Username!<br/>';
unset($username);
}
include("../join.php"); // Show form again
exit();
}

function makeRandomPassword() {
  $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  srand((double)microtime()*1000000); 
      $i = 0;
      while ($i <= 7) {
            $num = rand() % 33;
            $tmp = substr($salt, $num, 1);
            $pass = $pass . $tmp;
            $i++;
      }
      return $random_password;
}

$random_password = makeRandomPassword();

$db_password = md5($random_password);

$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, signup_date, 

decrypted_password)
        VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', now(), '$random_password')") or die (mysql_error());

if(!$sql){
    echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
    $to = '$email_address';
    $subject = 'Your Membership at owpt.biz';
    $message = 'Dear $first_name $last_name,
    You are now registered at our website, http://www.owpt.biz!
   
    To activate your membership, please login here: http://www.owpt.biz/home/index.php
   
    Once you activate your membership, you will be able to login with the following information:
    Username: $username
    Password: $random_password
    Please keep this username and password in a location that is easily accessible by you.
   
    Thanks!
    WebMaster, Owpt.biz
   
    This is an automated response, please do not reply!';
    $headers = "From: noreply@owpt.biz\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";
    mail($to, $subject, $message, $headers);
    echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
}
?>[/code]

At this point I am  :chomp: here is a copy of my php.ini

[code][mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = example@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\Program Files\xampp\sendmail\sendmail.exe -t"[/code]

here is a section of the php.ini

also here is a copy of the complete script(revised)

[code]<?php
include 'db.php';
$first_name = $_POST['first_name'];
$lastname_name = $_POST['last_name'];
$username = $_POST['username'];
$email_address = $_POST['email'];

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$username = stripslashes($username);
$email_address = stripslashes($email);

# Any errors in the posted fields? Lets check...
if((!$first_name) || (!$last_name) || (!$email) || (!$username)){
echo 'You did not submit the following required information! <br/>';
if(!$first_name){
echo '<font id=UserNameRed />First name <font id=UserPanelText />is a required field. Please enter it below. <br/>';
}
if(!$last_name){
echo '<font id=UserNameRed />Last name <font id=UserPanelText />is a required field. Please enter it below. <br/>';
}
if(!$email){
echo '<font id=UserNameRed />Email address <font id=UserPanelText />is a required field. Please enter it below. <br/>';
}
if(!$username){
echo '<font id=UserNameRed />Username <font id=UserPanelText />is a required field. Please enter it below. <br/>';
}
include("../join.php");
exit();
}

$sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if(($email_check > 0) || ($username_check > 0)){
echo 'Please fix the following errors: <br/>';
if($email_check > 0){
echo '<strong>Your email address has already been used by another member in our database. Please use a different Email address!<br/>';
unset($email);
}
if($username_check > 0){
echo 'The username you have selected has already been used by another member in our database. Please choose a different Username!<br/>';
unset($username);
}
include("../join.php"); // Show form again
exit();
}

function makeRandomPassword() {
  $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  srand((double)microtime()*1000000); 
      $i = 0;
      while ($i <= 7) {
            $num = rand() % 33;
            $tmp = substr($salt, $num, 1);
            $pass = $pass . $tmp;
            $i++;
      }
      return $random_password;
}

$random_password = makeRandomPassword();

$db_password = md5($random_password);

$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, signup_date, 

decrypted_password)
        VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', now(), '$random_password')") or die (mysql_error());

if(!$sql){
    echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
    $to = '$email_address';
    $subject = 'Your Membership at owpt.biz';
    $message = 'Dear $first_name $last_name,
    You are now registered at our website, http://www.owpt.biz!
   
    To activate your membership, please login here: http://www.owpt.biz/home/index.php
   
    Once you activate your membership, you will be able to login with the following information:
    Username: $username
    Password: $random_password
    Please keep this username and password in a location that is easily accessible by you.
   
    Thanks!
    WebMaster, Owpt.biz
   
    This is an automated response, please do not reply!';
    $headers = "From: noreply@owpt.biz\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";
    mail($to, $subject, $message, $headers)or die('something went wrong');
    echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
}
?>[/code]
Link to comment
Share on other sites

I think you might need to check your code, it looks like you need to make sure that you have closed any if's. I would sugest that you put some echos in to see where you get to in the script.  :)
Link to comment
Share on other sites

[quote author=redarrow link=topic=99389.msg391406#msg391406 date=1152015624]
Test the mailing code on it's own to see if you can send mail in genrall then youve ruled that out ok.
[/quote]

I tried testing it and I got the same thing. I recieved the message that the mail had been sent but it never was.
I guess that I will try and figure out what is wrong with Mercury Mail.
Link to comment
Share on other sites

Are you utilising a windows server with IIS as your web server?
I had issues on a setup with this, and in the end I found another mail class function:
http://phpmailer.sourceforge.net/

That's the solution I used, and now it's all working great. When I used an apache webserver, I managed to use the mail function without trouble, most likely smtp difficulties on the windows server, but the admin said the smtp was set up correctly. Took the best part of a day to sort, and if you are still having trouble - I'd suggest trying that phpmailer.
Link to comment
Share on other sites

I fixed the problem. The problem was an issue with windows and mercury mail.  It took along time and alot of reading but I finally got it to work

<b>*The Fix</b>

It was rather simple realy. There is an issue with using the X-mailer and the Mecury Mail Server. I had to change my send mail script

[color=red]<b>From:</b>[/color]

[code]    $to = '$email_address';
    $subject = 'Your Membership at owpt.biz';
    $message = 'Dear $first_name $last_name,
    You are now registered at our website, http://www.owpt.biz!
   
    To activate your membership, please login here: http://www.owpt.biz/home/index.php
   
    Once you activate your membership, you will be able to login with the following information:
    <b>Username:</b> <font color=\"#FF0000\">$username</font>
    <b>Password:</b> <font color=\"#FF0000\">$random_password</font>
    Please keep this username and password in a location that is easily accessible by you.
   
    Thanks!
    WebMaster, Owpt.biz
   
    This is an automated response, please do not reply!';
    $headers = "From: noreply@owpt.biz\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";
    mail($to, $subject, $message, $headers)or die('something went wrong');
    echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
}
[/code]

[color=red]<b>To:</b>[/color]

[code]$knownsender = "webmaster@owpt.biz";
$mailtos = "$email_address";
$subject = "Your Membership at owpt.biz";
$message = "Dear $first_name $last_name,
    You are now registered at our website, http://www.owpt.biz!
   
    To activate your membership, please login here:
    http://www.owpt.biz/home/index.php
   
    Once you activate your membership, you will be able to login
    with the following information:
    Username: $username
    Password: $decrypted_password
    Please keep this username and password in a location that is easily
    accessible by you.
   
    Thanks!
    WebMaster, Owpt.biz
   
    This is an automated response, please do not reply!";
   
   
}
if ($ccaddress=="" || $ccaddress==" ")
{
$header="From: $knownsender";

}
else
{
$header .="From: $knownsender\r\n";
$header .=" Cc: $ccaddress";
}
// $header.="Bcc: $bcaddress";

if (@mail($mailtos, $subject, $message, $header))
{
echo "Your Registration Email has been sent. Please check your email and follow the instructions";
}
else
{
echo "There was an error sending your Registration Email";
}[/code]

I posted the fix in hopes that it may help someone else some day. I am not sure if this is the most secure way to send the email or not but it works.
Link to comment
Share on other sites

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.