Jump to content


Photo

Php mail not sending mail


  • Please log in to reply
10 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 04 July 2006 - 09:37 AM

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

} 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!'; 
} 
?>

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 July 2006 - 09:56 AM

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);

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 04 July 2006 - 10:54 AM

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.

     $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);

And here is another one that I have tried

    $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()); 


Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 zawadi

zawadi
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationChippenham UK

Posted 04 July 2006 - 10:54 AM

do you gat any error messages?
That's the beauty of asymmetric warfare. You don't need a lot of money, or an army of people. You can do it from the comfort of your living room, with a beer in your hand.

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 July 2006 - 11:07 AM

none of the codes work so cheek your php.ini settings then.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 04 July 2006 - 12:11 PM

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

<?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!'; 
} 
?>

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

[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"

here is a section of the php.ini

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

<?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!'; 
} 
?>

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 July 2006 - 12:20 PM

Test the mailing code on it's own to see if you can send mail in genrall then youve ruled that out ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 zawadi

zawadi
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationChippenham UK

Posted 04 July 2006 - 12:38 PM

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.  :)
That's the beauty of asymmetric warfare. You don't need a lot of money, or an army of people. You can do it from the comfort of your living room, with a beer in your hand.

#9 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 04 July 2006 - 01:35 PM

Test the mailing code on it's own to see if you can send mail in genrall then youve ruled that out ok.


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.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#10 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 04 July 2006 - 01:47 PM

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.

#11 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 08 July 2006 - 01:21 AM

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

<b>From:</b>

    $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!'; 
} 

<b>To:</b>

$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";
}

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.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users