Nov 22, 2009

Mail() Not Working

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Mail() Not Working

Linneus
I'm trying to use the mail() function in a script. But it doesnt work. It keeps returning false.
It's a premade script
The code is:

CODE
function SendPassword($userName)
{

global $db,$db_tables;//config.php
    // set password for username to a random value
    // return the new password or false on failure
    $new_password = mt_rand();

    $qry = "UPDATE $db_tables[Users] SET password=password('$new_password') WHERE user_name='$userName'";
    $db->db_query($qry);

    // send notification email
    $from = "From: $from_email\r\n";
    $msg = "You or someone pretending to be you has requested that your"
 . "password be changed for your bookmark account hosted at http://$domain/$subdir\r\n\r\n"
 . "Your account password has been changed to $new_password\r\n"
 . "Please change it next time you log in.\r\n";
    
    if (!mail("$email", "Login information", $msg, $from))
    {
   echo "ERROR : Unable to send notification email.  Please contact the <a href=\"mailto:$admin@$domain\">Administrator</a>";
    }
}

 

 

 


Comment/Reply (w/o sign-up)

rkage
Just a few questions to help me see whats wrong;

Are you sure your host allows the mail function (if not using Astahost)?
When you say return false, do you mean it shows the "Contact admin" self made error or it displays a PHP error?

Also try doing just this;

CODE
mail("$email", "Login information", $msg, $from)


See if that returns a PHP error when you try to send it. I'm not sure which part of the mail script isn't working but why is there quotes round the email but not the msg and from?

I'll try helping you once you reply, it's hard for me to test scripts that rely on databases since if the database isn't functioning a code properly, it will return an error and hence the rest will not work and return an error.

Comment/Reply (w/o sign-up)

Linneus
[/QUOTE]I have changed to code to:

CODE
function SendPassword($userName)
{

global $db,$db_tables;//config.php
    // set password for username to a random value
    // return the new password or false on failure
    $new_password = mt_rand();

    $qry = "UPDATE $db_tables[Users] SET password=password('$new_password') WHERE user_name='$userName'";
    $db->db_query($qry);

    // send notification email
    $from = "From: $from_email\r\n";
    $msg = "You or someone pretending to be you has requested that your"
 . "password be changed for your bookmark account hosted at http://$domain/$subdir\r\n\r\n"
 . "Your account password has been changed to $new_password\r\n"
 . "Please change it next time you log in.\r\n";
    
    if (!mail($userName, "Login information", $msg, $from))
    {
   echo "ERROR : Unable to send notification email.  Please contact the <a href=\"mailto:$admin@$domain\">Administrator</a>";
    }
}


Now it doesnt show it self made error message. But I don't get any mail from it. Anyway all usernames are email-addresses. I've tried to change

CODE
if (!mail($userName, "Login information", $msg, $from))


to

CODE
if (!mail("linneuscool@hotmail.com", "Login information", $msg, $from))


linneuscool@hotmail.com is my email-address. But it doesnt even work then.

 

 

 


Comment/Reply (w/o sign-up)

rkage
Did you try the mail on it's own without any IF statements. I know there are some functions that won't work when nested in an if statement. I really can't see what is wrong. If this is a premade script it should be working... Just to verify, and it may be stating the obvious, but you are sure your host allows the mail command and that you are checking your inbox, including any junkmail filters?

Comment/Reply (w/o sign-up)

Linneus
It works now. It was in spam-box because I had no sender in the mail.

Thank you tongue.gif

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : mail, working

  1. Can't Make This Query Working.
    (2)
  2. Using Php With A Mail Server
    (2)
    We all know you can use PHP with a web server, but can you use it with a mail server? I've made
    a personal messenger system, and I was thinking about adding additional functionality in the future,
    such as the ability to send mail from it. Then I started thinking, would it be possible to recieve
    mail with it? Say, have a PHP script that checked when a message arrived at the server, and when it
    does, check for something in the message (e.g. "pmsystem-to: admin") that would tell it to send it
    to a certain user, and then have it do the scripts to send a PM. So, is it....
  3. PHP: Need Help Sending Mail Using SMTP
    (5)
    While the mail() function of php is all bout simplicity, it lacks the otherwise necessary
    flexibility. How do I send an E-Mail using php through SMTP?....
  4. Installed A PR Checker Script - But Not Working Correctly
    (6)
    I'm new to PHP and still have much to learn. I came across a free script to check google PR.
    You place a file called pagerank.php and then have an includes. So I did this: CODE ?>
    Then I have my HTML (the page header and so forth), and added a form where they can input their URL.
    The form action is CODE " method="post" name="checkpr" id="checkpr"> First of all ... I
    seem to be missing something completely basic. My page isn't displaying at ALL as I expected.
    No graphic header and no form. It's actually showing all my HTML code in....
  5. Php Send Mail Through Smtp
    (10)
    Can anyone here tell me how to send mail through SMTP server with php /mellow.gif"
    style="vertical-align:middle" emoid=":mellow:" border="0" alt="mellow.gif" /> I have search in many
    source code on web and cant find anything /sad.gif" style="vertical-align:middle" emoid=":("
    border="0" alt="sad.gif" />....
  6. E-mail List Error
    (4)
    I just coded this e-mail list, it works well for entering data into database, but if user leaves
    the field blank or adds an already exist e-mail it gives him the error message and stops loading the
    rest of the page. CODE // Connects to your Database mysql_connect("localhost", "my_username",
    "mypassword") or die(mysql_error()); mysql_select_db("Database name") or die(mysql_error()); //This
    code runs if the form has been submitted if (isset($_POST )) { //This makes sure they did not leave
    any fields blank if (!$_POST ) {die(' No e-mail added '); } ....
  7. Using The Php Mail() Function For Images Or Attachments
    Can't find a decent tutorial! (6)
    I read the one mail() tutorial that was posted in the tutorial section and to my horror found that
    he had quoted almost verbatim from the PHP Manual off php.net, and made a comment about it, and also
    found that if you were new to PHP or the Manual that it was informative but not indepth enough for
    my tastes. This is not a tutorial although with the code that will be posted it might look like
    one, that is not its intent or purpose. I have searched and found many so called tutorials about
    MIME mail and boundries and all that but basically it either told me to use PHPMai....
  8. Sending Mail To A Mailing List
    Possibility of sending a newsletter (12)
    Task : To send an email to a list of email addresses stored in a database Premise : Page is
    written in PHP, with the database as MySQL. The email addresses need to be taken from a column of a
    table in the database which is queried with some "WHERE" clause. The email sent to these addresses
    is static. Objective : To send a newsletter to the members who have subscribed for the same on a
    website. Well, there. I have put it as objectively and as clearly as possible. I have searched
    for the keywords "mail" and "PHP" on this section of the forum, and from what I have....
  9. Simple E-mail Validation
    check for correct address and syntax (2)
    Hey , this tutorial will tell you a very simple way to check if email addresses entered are with the
    correct syntax. Hope this will help you eliminate jokers. So this script will... (check the
    characters, and check if there is a " someone somewhere.extension ". Ok, so firstly we create a
    function with all the invalid stuff in it:- CODE function CheckMail($email) { if (eregi("^ ( ?
    )*@ ( ? )*\. {2,4}$", $email)) { return true; } else { return false; } } Now, to check an
    email you just run the variable with the email in it through the function as follow....
  10. Php Wget
    Its not working!!! (3)
    A while ago I posted a thread asking if anyone knew anything about wget, and I was given the code
    below: CODE $foo = system('wget http://www.whatever.com/file.html ~',$output); ?>
    Which has been working fine, since the panda server failure a while ago. Since then, whenever I try
    to use it , it comes up with QUOTE $foo = system('wget
    http://www.gallifreyone.com/forum/customav...avatar646_8.gif ~',$output); ?> Has this been
    disabled by the administrators, or is there a way I can sort it out?....
  11. Do You Want A Mail Form In Your Site
    (2)
    Notice from m^e: Repeat post. Credits reduced by 5 days. Learn to USE
    THE SEARCH BUTTON before you make such posts. did you want to have in your web site mail form
    that allow the user to send mails to anther mail from his mail e.g. the compose in yahoo CODE
    from to cc bcc subject
    function param($Name)         {         global
    $HTTP_POST_VARS;         if(isset($HTTP_POST_VARS ))            return($H....
  12. Form Mail Php - Use Php To Send Form Through Email
    (8)
    Just sends all form data to a specified email. Does anyone know a free script that does this?....
  13. A Php Gallery Commenting Script Question...
    i am working on a php script... (2)
    Hi all, i am working on a Gallery commenting script for myself and i got stuck at a part of it. I
    would like each new comment added to an image to be a number as the text file name like 1, 2, 3.
    everytime they add a comment the next file name is incremented (+1) and so on for example; if there
    was a text file names '1' then the next would be named '2'. I know how to create
    the file and the rest of it, but i would like to know how to do this. I should probably store the
    last file name somehow and then add 1 to it to create the next file but i do not know....
  14. Php Problem - Unique Counter
    my script isn't working correctly (4)
    alright here's what I want to do: I made a counter to count unique visitors without a mysql. But
    the problem is that the '.dat' file I'm writing on (unique.dat) tends to become too big
    when I have too many visitors. Thus, I tried to add an if/then statement. Kay, now here's the
    problem: even though this code successfully runs, it's not a hundred-percent accurate. Sometimes
    it rewrites a user's IP even though it is already on the '.dat' file. Even though it
    doesn't actually affect the $hits, I'd still like to know what I did w....
  15. Php Problem Error Message
    I'm working from a book (9)
    I get this error message when I try to view a small webpage. QUOTE Parse error: parse error,
    unexpected T_STRING, expecting ',' or ';' in
    /home/nilsc/public_html/bobs/processorder.php on line 27 Line 27 is in this php part: CODE
        echo ' Order processed. ';     echo $tireqty. ' tires ';     echo $oilqty. '
    bottles of oil ';     echo $sparkqty. ' spark plugs ';          $totalqty = 0;
        $totalqty = $tireqty + $oilqty + $spakqty;     echo 'Items ordered: ' .$totalqty.' ;
             $totalamount = 0.....
  16. How To Set Up Form Mail
    (4)
    I am programming on a web site's contact form page, How can I mail the filled in information of
    the client to particular E-mail address? I tried form action="mailto:blah@blah", but it is running
    all right on my machine rather that other computer in our LAN. The error message I got is a
    connection failure error occurred. I noticed there are some form mail info on line, but I have no
    idea to figure out how is that works. Anybody have some experience on that? Thanks!....

    1. Looking for mail, working

See Also,

*SIMILAR VIDEOS*
Searching Video's for mail, working
advertisement



Mail() Not Working

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com