SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Mail in PHP

  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mail in PHP

    Hi,

    I have a simple Mail problem. I'm trying to let my members send an email using a form from inside the members area to their referrals.

    Everything is working fine, and the email is being sent. However, the name of the sender is not appearing in the FROM field, neither does his/her email address.

    I want people to be able to hit the reply bottom and reply to the sender.

    Here is the handling script which the referer is taken to after he submits his form

    PHP Code:
    <?
    session_start
    ();
    if (!isset(
    $_SESSION['username'])) {
    die(
    'An error has ocurred. You have not logged in, or your session has expired.');
    exit();
    }

    $dbcnx = @mysql_connect("localhost""user""pass");
       if (!
    $dbcnx) { 
         echo( 
    "<p>Unable to connect to the " 
               
    "database server at this time.</p>" );
         exit(); 
       }

    // Select the database
       
    if (! @mysql_select_db("referlive_com") ) {
         echo( 
    "<p>Unable to locate the " .
               
    "database at this time.</p >" ); 
         exit(); 
       }
       
    $sql mysql_query("SELECT * FROM users WHERE username='$username'");
    $lookup mysql_fetch_assoc($sql);
    $hisemail $loopup['emailaddress'];
    $hisfirst $lookup['firstname'];
    $hislast $lookup['lastname'];
       

    $message $_POST['message'];
    $subject $_POST['subject'];

    if ((!
    $message) || (!$subject)) {
                    echo 
    'You forgot to enter a message and/or a subject. Please go back and correct this.';
                    exit();
                    }
                    
    $sql2 mysql_query("SELECT * FROM users WHERE referer='$username'");

    while(
    $row mysql_fetch_array($sql2)) {
    $theiremails $row['emailaddress'];
    mail($theiremails$subject$message
    "From: $hisfirst $hislast <$hisemail>\nX-Mailer: PHP/" phpversion());
    }

    echo 
    'Your email has been sent. You are being forwarded back to the members area.';

    ?>
    The receivers will receive the email. But the sender name and email address is not being received!

    I apperciate you help.

    Jimmy.

  2. #2
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try perhaps using mysql result instead of fetch_assoc? Like...
    $hisemail = mysql_result($sql,0,"emailaddress");
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Toly
    Did you try perhaps using mysql result instead of fetch_assoc? Like...
    $hisemail = mysql_result($sql,0,"emailaddress" );
    mysql_fetch_assoc() is mostly the same as mysql_fetch_array(). It is better, stronger and faster than mysql_result().

    Jimmy, for a starters, this line is incorrect. $loopup?
    PHP Code:
    $hisemail $loopup['emailaddress']; 
    Try fixing that, it may affect the displaying of the senders name as currently no email address is being set.

  4. #4
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd seriously take a look at phpMailer: http://phpmailer.sourceforge.net/ - this is a class which basically handles everything you'll ever need to do with email, such as attachements, HTML mail etc. You may find this tutorial helps you understand how to use it.

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I must need glasses! It was the spelling error ($loopup). Thank you guys for your help

    I'm trying to give my members a chance to email their personal referrals. Let's say someone bring in 100 or 200 referrals.

    When he emails them all, will that cause any problems on the server because of the large number of referrals? Will he/she has to stay on the page for x seconds?

  6. #6
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use

    http://www.php.net/manual/en/functio...user-abort.php

    Then the user can "bail out" whenever he/she feels like it .


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •