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.

sending email

Discussion in 'PHP' started by ahmedmii, Aug 7, 2011.

  1. #1
    Hello,I'm new in php ,and I've been trying to send email using this code .I found in w3schools.com
     
    ahmedmii, Aug 7, 2011 IP
  2. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #2
    And what is the question? :)
     
    bogi, Aug 7, 2011 IP
  3. ahmedmii

    ahmedmii Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My question is how to send email?
     
    ahmedmii, Aug 7, 2011 IP
  4. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #4
    As I don't know what script you tried, try this:

    
    <?php
    
    $to      = 'recipient@example.com'; // change this to the recipient's email address
    $subject = 'This is the subject of your email';
    $message = 'This is the message';
    $from    = 'From: Sample Sender <sender@example.com>'; // change this to the sender's name and email address
    
    if ( mail($to, $subject, $message, $from) ) {
    	
    	echo "Email has been successfully sent by mail() function.<br />\n";
    }
    else {
    	
    	echo "Oops, it seems something went wrong...<br />\n";
    }
    
    ?>
    
    PHP:
     
    bogi, Aug 7, 2011 IP
    igloodesigns likes this.
  5. ModulesGarden

    ModulesGarden Active Member

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    58
    #5
    The code Bogi provided is not working always.
    If you will have problems, try to use PHPMailer library - it is simple and there is a lot of documentation, sample scripts that will help you.
     
    ModulesGarden, Aug 7, 2011 IP
  6. FilesIN

    FilesIN Member Affiliate Manager

    Messages:
    94
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    33
    #6
    The simple way to send email via php :

    
    mail ($to_email , $subject ,  $message , $additional_headers);
    
    PHP:
     
    FilesIN, Aug 7, 2011 IP
  7. ahmedmii

    ahmedmii Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It gave me this message Network Error (dns_unresolved_hostname) Your requested host "google.aramcoservices.com" could not be resolved by DNS. For assistance, contact your network support team.
     
    ahmedmii, Aug 7, 2011 IP
  8. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #8
    It seems your host doesn't allow sending emails.
     
    bogi, Aug 7, 2011 IP
  9. shiva88

    shiva88 Member

    Messages:
    270
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #9
    try this one... its perfectly working code

    $subject = 'the subject';
    $message = 'hello';
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: DealsToDO '.$fromAdd.''. "\r\n";
    $mail = @mail($toAdd, $subject, $message, $headers);

    echo $mail . if you get output 1 then mail sent is success else null means their is some error in server or html template..

    this script is for both text as well as html template mail like Newsletters...
     
    shiva88, Aug 8, 2011 IP
  10. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #10
    It also won't work because of this:

     
    bogi, Aug 8, 2011 IP
  11. ahmedmii

    ahmedmii Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I tried with a new host .Now ,it give me this messageObject not found!The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again. If you think this is a server error, please contact the webmaster. Error 404localhost8/8/2011 10:45:56 AMApache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
     
    ahmedmii, Aug 8, 2011 IP
  12. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #12
    It's just a simple 404 error message, meaning the URL you entered wasn't found. Make sure the URL you typed is correct - check the spelling, CApItalIZAtion etc :)
     
    bogi, Aug 8, 2011 IP
  13. ahmedmii

    ahmedmii Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    NO,the spelling corret look
     

    Attached Files:

    • 1.jpg
      1.jpg
      File size:
      94.5 KB
      Views:
      159
    ahmedmii, Aug 8, 2011 IP
  14. ahmedmii

    ahmedmii Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I'm using xampp, could it be because of it....
     
    ahmedmii, Aug 8, 2011 IP
  15. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #15
    When you say you're using xampp, I'm assuming your using your home PC as the server. The PHP mail() function never worked for me on xampp cuz there are a lot of technical configurations that must be done. Most, if not all shared hosting providers, the code provided above will work.
     
    Andre91, Aug 8, 2011 IP
  16. ahmedmii

    ahmedmii Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Do you know software like xampp that doesn't need alot of configurations ,and also it's free ?
     
    ahmedmii, Aug 8, 2011 IP
  17. TsubasaOzora

    TsubasaOzora Well-Known Member

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    113
    #17
    try appserv
     
    TsubasaOzora, Aug 9, 2011 IP
  18. igloodesigns

    igloodesigns Member

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #18
    <?php
    $to = "someone@example.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "someonelse@example.com";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
    ?>
    PHP:
    Also, here's a simple script using a form setup:

    <html>
    <body>
    <?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
      {
      //send email
      $email = $_REQUEST['email'] ;
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;
      mail("someone@example.com", "$subject",
      $message, "From:" . $email);
      echo "Thank you for using our mail form";
      }
    else
    //if "email" is not filled out, display the form
      {
      echo "<form method='post' action='mailform.php'>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' />
      </form>";
      }
    ?>
    </body>
    </html>
    PHP:
     
    igloodesigns, Aug 12, 2011 IP
  19. ahmedmii

    ahmedmii Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    I think the problem ,there's some configurion for xampp to send email, but the problem as I mentioned befor I'm in this language.So,if someone knows how configure xampp,post plz?
     
    ahmedmii, Aug 13, 2011 IP
  20. freelanceinphp

    freelanceinphp Member

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #20
    freelanceinphp, Aug 15, 2011 IP