CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2009
    Posts
    6

    Unhappy problem in sending mail through mail function in php

    I made file one is html that is

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html>
    <head><title>Mail sender</title></head>
    <body>
    <form action="mail.php" method="POST">
    <b>Email</b><br>
    <input type="text" name="email" size=40>
    <p><b>Subject</b><br>
    <input type="text" name="subject" size=40>
    <p><b>Message</b><br>
    <textarea cols=40 rows=10 name="message"></textarea>
    <p><input type="submit" value=" Send ">
    </form>
    </body>
    </html>
    and one for php for sending mail that is


    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head><title>PHP Mail Sender</title></head>
    <body>
    <?php

    /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
    $email $HTTP_POST_VARS['email'];
    $subject $HTTP_POST_VARS['subject'];
    $message $HTTP_POST_VARS['message'];

    /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
    if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/"$email)) {
      echo 
    "<h4>Invalid email address</h4>";
      echo 
    "<a href='javascript:history.back(1);'>Back</a>";
    } elseif (
    $subject == "") {
      echo 
    "<h4>No subject</h4>";
      echo 
    "<a href='javascript:history.back(1);'>Back</a>";
    }

    /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
    elseif (mail$email,$subject,$message,"hhh")) {
      echo 
    "<h4>Thank you for sending email</h4>";
    } else {
      echo 
    "<h4>Can't send email to $email</h4>";
    }
    ?>
    </body>
    </html>
    and when i run this through html form it through this error

    Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in e:\amit\wamp\www\pp\mail.php on line 22

    Can't send email to [email protected]
    i can i get any solution plz help me out
    as soon as possible
    Last edited by PeejAvery; July 30th, 2009 at 08:45 AM. Reason: Added code and PHP tags.

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    106

    Re: problem in sending mail through mail function in php

    http://nl3.php.net/manual/en/function.mail.php

    Note: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
    Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.


    PHP Code:
    <?php
    $to      
    '[email protected]';
    $subject 'the subject';
    $message 'hello';
    $headers 'From: [email protected]"\r\n" .
        
    'Reply-To: [email protected]"\r\n" .
        
    'X-Mailer: PHP/' phpversion();

    mail($to$subject$message$headers);
    ?>
    Last edited by Teranoz; July 30th, 2009 at 09:34 AM. Reason: code tags to php tags

  3. #3
    Join Date
    Jul 2009
    Posts
    6

    Re: problem in sending mail through mail function in php

    still throw ing warning s

    Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for [email protected] in e:\amit\wamp\www\pp\dd.php on line 15

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <?php
    $to      = '[email protected]';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: [email protected]' . "\r\n" .
        'Reply-To: [email protected]' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    ?>
    <body>
    </body>
    </html>
    Last edited by PeejAvery; July 30th, 2009 at 08:46 AM. Reason: Added code tags.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: problem in sending mail through mail function in php

    You haven't properly configured your SMTP settings inside of the php.ini configuration file. Do you have an SMTP server?

    Also...Please use &#91;code&#93; or &#91;php&#93; tags. BB code
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    106

    Re: problem in sending mail through mail function in php

    Quote Originally Posted by amitpant_5 View Post
    still throw ing warning s

    Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for [email protected] in e:\amit\wamp\www\pp\dd.php on line 15
    This means it does work but is not allowed, because the server does not allow that gmail address as sender.
    Try using a valid email adres with the domain of the website.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured