1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP email help

Discussion in 'PHP' started by maherov, Jun 18, 2008.

  1. #1
    I have a site hosted with godaddy.com

    I made a form and i want it to send a confirmation email to whoever filled it out, i tried the mail() function for php in a if-else statement

     if (mail( $email, "Subject: $subject",
      $message, "From: $email", "Order : $quantity"))
      {
      echo("<p>Message successfully sent!</p>");
      }
      else {
      echo("<p>Message delivery failed...</p>");
      }
    Code (markup):
    i kept getting Message delivery failed.

    Godaddy's gdform.php works, but it only sends the email to me and i cant figure out how to edit it to send the email to the person who filled out the form.

    i came to a conclusion that SMTP is not working on the page, i tried another piece of code
    <?php
    require_once "Mail.php";
    
    $from = "Sandra Sender <sender@example.com>";
    $to = "Ramona Recipient <recipient@example.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";
    
    $host = "mail.example.com";
    $username = "smtp_username";
    $password = "smtp_password";
    
    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password));
    
    $mail = $smtp->send($to, $headers, $body);
    
    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }
    ?>
    Code (markup):
    but that didnt work either

    any help would be appreciated

    thanks
    SEMrush
     
    maherov, Jun 18, 2008 IP
    SEMrush
  2. melol2

    melol2 Active Member

    Messages:
    511
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #2
    
     if (mail( $email, "Subject: ".$subject,
      $message, "From: ".$email, "Order : ".$quantity))
      {
      echo("<p>Message successfully sent!</p>");
      } else {
      echo("<p>Message delivery failed...</p>");
      }
    
    PHP:
    Not sure if this is your problem but you were reading the variables as text. use "." to fuse text and variables such as "Order: ".$quantity
     
    melol2, Jun 18, 2008 IP
  3. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #3
    $quantity  = 10;
    
    echo "Quantity : $quantity";     //<----- output Quantity : 10;
    echo 'Quantity : $quantity';    //<------ output Quantity : $quantity;
    
    PHP:
     
    php-lover, Jun 18, 2008 IP
  4. melol2

    melol2 Active Member

    Messages:
    511
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #4
    hmm. You're right. My mistake. I learned something today. Thanks :)
     
    melol2, Jun 18, 2008 IP
  5. maherov

    maherov Peon

    Messages:
    198
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    anyone else?
     
    maherov, Jun 19, 2008 IP
  6. livingearth

    livingearth Well-Known Member

    Messages:
    1,470
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #6
    I do not understand you use of the if statement..
    I would use the mail command directly..
    Or better yet pass the variables to an external file which would send data and display results...
     
    livingearth, Jun 19, 2008 IP
  7. livingearth

    livingearth Well-Known Member

    Messages:
    1,470
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #7
    
    <?php
    $hostname = gethostbyaddr($REMOTE_ADDR);
    ?>
    <?php
    mail( "info@youdomain.com", "Mail From Your Website ","From IP $REMOTE_ADDR
    Provider - $hostname 
    Browser - $HTTP_USER_AGENT
    
    Name - $name
    Email - $user_email
    Address - $address
    $city - $state -$country
    
    Message...
    
    $message", "From: mailForm\@yourdomain.com" );
    ?>
    <?php
    mail( "yourname@yourdomain.com", "Mail From Your Website ","From IP $REMOTE_ADDR
    Provider - $hostname 
    Browser - $HTTP_USER_AGENT
    
    Name - $name
    Email - $user_email
    Address - $address
    $city - $state -$country
    
    Message...
    
    $message", "From: mailForm\@yourdomain.com" );
    ?>
    <?php
    echo("<body background=skybluerevgrad.gif><br><p><center><font color=black size=+2 face=arial><b>Thank You!<br> The following message has been sent to Your Company <br> You will recieve a reply as soon as it has been processed...<p>
    
    <table width=80%><tr><td>
    <font color=#0000aa size=+1 face=arial>Name -</font></b> $name<br>
    <font color=#0000aa size=+1 face=arial><b>Email -</font></b> $user_email<br>
    <font color=#0000aa size=+1 face=arial><b>Address -</font></b> $address $city $state $zip $country<p>
    
    <font color=#0000aa size=+1 face=arial><b>Message...</font><p>
    
    </b>$message</td></tr></table>");
    ?>
    
    Code (markup):
     
    livingearth, Jun 19, 2008 IP
  8. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #8
    Check to make sure that PEAR Mail package is installed in your server.
    Make sure you pass correctly the email of the person who filled out your form.
     
    php-lover, Jun 19, 2008 IP
  9. maherov

    maherov Peon

    Messages:
    198
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    from what i read, PEAR is part of PHP core and does not require installation. and as for the email addresses, i assigned the email to the variable directly and tried it and it wont work.
     
    maherov, Jun 19, 2008 IP