Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail function - what am I doing wrong ?

Status
Not open for further replies.

DaSe

Programmer
Feb 14, 2008
149
GB
Hi PHP guys, for some time I've been modifying the mail() function and absolutely have no clue why it doesn't send an activation link to a user mail. Ok so the code is:

-------------
mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error());
echo "<html><br/><br/>Account created.</html>";

$to = "$email";

$from = "admin@muciooler.net";
$subject = "Complete yourdomain registration";
//Begin HTML Email Message
$message = "Hi $firstname,



If the URL above is not an active link, please copy and paste it into your browser address bar

Login after successful activation using your:
E-mail Address: $email
Password: $password

See you on the site!
admin@musicooler.net";
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n";

mail($to, $subject, $message, $headers);

$msgToUser = "<h2>One Last Step - Activate through
Email</h2><h4>OK $firstname, one last step to verify your email identity:</h4><br />"

--------------------------------------
Just thanks for any comments!
 
What error code do you get back from the mail function?

Have you checked your variables to make sure that they contain the data you expect them to have?

Have you sent mail from your server before?

Have you tried sending a simple test message to yourself?
 
Hey, yes. I've been trying to send a simple message to my outlook mail - to no avail. What i did was to implement a simple script:

----
$email = mysql_real_escape_string($_POST['email']);

$sql = mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')")

if ($sql) {

$to="$email";
$from = "admin@mypage.net";
$subject = "Complete yourdomain registration";

mail($to,$from,$subject);
}

-------
So I'm stuck a bit..
 
When I say simple I mean

<?php
$return=1;

$return=mail('myMail@myDomain.com','Subject','From: myOtherEmail@myDomain.com X-Mailer: PHP/');

echo $return;?>


What about my other questions?
 
Look like your script it's working fine. The browser shows
"1" with no errors.

For other questions :
1.) I checked the variables - they seem to be ok ,
2.) No I've never used it before, I'm a newbie to PHP rather,
3.) I've been trying to send a simple message to myself - to no avail.

 
I'm assuming you replaced the email addresses in my sample with real addresses. If that the case and the script returns a 1 its working. This means that the problem is either in mail setup on the server or the mail is being blocked by the receiver.

Unfortunately I don't know how to help you from here.
 
actually alan's code is unlikely to give you the right response, although the principle is sound.

try this

Code:
$myAddress = 'email@domain.com'; //replace with working adddress
mail($myAddress, 'subject', 'this is a test message', "From: $myAddress\r\n") or die ('error in mail function');
echo 'mail delivered to MTA ok';

if you get no errors, this means that php is handing off the email to the operating system or external program and is not finding fault. On *nix based systems typically php uses sendmail to interface with the smtp server. on windows it hooks directly into the smtp server specified in php.ini.

so, it would help to know which OS you are using and whether you have set up your smtp server and sendmail.

the most common fault is that you have forgotten to enable relaying from your IP address using your smtp server. Many MTA's require you to enable this specifically.

if you have no control over your MTA and cannot get it working then you should try phpmailer instead of mail(). it is just a set of scripts and there are plenty of examples on the web as to how to use phpmailer. The core advantage is that it comes with a built in smtp class to interface to your external SMTP host.
 
Thanks guys a lot, I'll try those options.
 
Hello guys one more time. Just to sum up:
Yes, the script above "the simple script" is working
======
$myAddress = 'email@domain.com'; //replace with working adddressmail($myAddress, 'subject', 'this is a test message', "From: $myAddress\r\n") or die ('error in mail function');echo 'mail delivered to MTA ok';
======

So how can I get my page working basing it on the above script. This is what I've been trying to do but so far it doesn't work:

=========

$tr = mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); echo "<html><br/><br/>Account created.</html>";
if($tr){
$to="$email";
mail('$to','Subject','From: admin@musicooler.net X-Mailer: PHP/');
}
=========
Thanks for any comments.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top