www.webdeveloper.com
Results 1 to 6 of 6

Thread: php mail not sending

  1. #1
    Join Date
    Jul 2006
    Posts
    373

    php mail not sending

    Hi,

    i have a web host and im trying to send php mail with this script:

    PHP Code:
    <?php
    mb_internal_encoding
    ('UTF-8');
    $name=$_POST['name'];
    $email=$_POST['email'];
    $subject=$_POST['subject'];
    $to  $_POST['target'];
    $message $_POST['message'];
    $from_name mb_encode_mimeheader($name,'UTF-8');
    $headers  "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=utf-8\r\n";
    $headers .= "To: $name <$to>\r\n";
    $headers .= "From: $from_name <$email>\r\n";
    mail($to$subject$message$headers);
    ?>
    <html>
     <head></head>
     <body>
      <FORM method="POST" action="mail.php">
     <TABLE class="reserve" cellpadding="0" width="100%" cellspacing="0" align="left">
      <TBODY>
       <TR> 
        <TD width="100%" colspan="2">
         <H1>Email form</H1>
        </TD>
       </TR>
       <TR>
        <TD align="left" valign="top" height="13px" width="20%">Name:</TD>
        <TD><INPUT type="text" name="name" size="20"></TD>
       </TR>
       <TR>
        <TD>Email:</TD>
        <TD><INPUT type="text" name="email" size="20"></TD>
       </TR>
       <TR>
        <TD>Target address:</TD>
        <TD><INPUT type="text" name="target" size="20"></TD>
       </TR>
       <TR>
        <TD>Subject:</TD>
        <TD><INPUT type="text" name="subject" size="20"></TD>
       </TR>
       <TR>
        <TD align="left" colspan="2">Message:</TD>
       </TR>
       <TR>
        <TD align="left"></TD>
        <TD><TEXTAREA name="message" rows="4" cols="32"></TEXTAREA></TD>
       </TR>
       <TR>
        <TD style="text-align:center" colspan="2"><input type="submit" value="SUBMIT"></TD>  
       </TR>
      </TBODY>
     </TABLE>
    </FORM>   
     </body>
    </html>
    But its not sending any mail. I guess its because of some server weird configuration. I have Linux CentOS. Could you please help me out?

    Thank you.

  2. #2
    Join Date
    Apr 2012
    Location
    Egypt
    Posts
    21
    but this if statement
    PHP Code:
    <?php
    mb_internal_encoding
    ('UTF-8');
    if(isset(
    $_POST['submit'])){
    $name=$_POST['name'];
    $email=$_POST['email'];
    $subject=$_POST['subject'];
    $to  $_POST['target'];
    $message $_POST['message'];
    $from_name mb_encode_mimeheader($name,'UTF-8');
    $headers  "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=utf-8\r\n";
    $headers .= "To: $name <$to>\r\n";
    $headers .= "From: $from_name <$email>\r\n";
    mail($to$subject$message$headers);
    }
    ?>
    <html>
     <head></head>
     <body>
      <FORM method="POST" action="mail.php">
     <TABLE class="reserve" cellpadding="0" width="100%" cellspacing="0" align="left">
      <TBODY>
       <TR> 
        <TD width="100%" colspan="2">
         <H1>Email form</H1>
        </TD>
       </TR>
       <TR>
        <TD align="left" valign="top" height="13px" width="20%">Name:</TD>
        <TD><INPUT type="text" name="name" size="20"></TD>
       </TR>
       <TR>
        <TD>Email:</TD>
        <TD><INPUT type="text" name="email" size="20"></TD>
       </TR>
       <TR>
        <TD>Target address:</TD>
        <TD><INPUT type="text" name="target" size="20"></TD>
       </TR>
       <TR>
        <TD>Subject:</TD>
        <TD><INPUT type="text" name="subject" size="20"></TD>
       </TR>
       <TR>
        <TD align="left" colspan="2">Message:</TD>
       </TR>
       <TR>
        <TD align="left"></TD>
        <TD><TEXTAREA name="message" rows="4" cols="32"></TEXTAREA></TD>
       </TR>
       <TR>
        <TD style="text-align:center" colspan="2"><input type="submit" name="submit" value="SUBMIT"></TD>  
       </TR>
      </TBODY>
     </TABLE>
    </FORM>   
     </body>
    </html>
    and give your submit property name=submit

  3. #3
    Join Date
    Jul 2006
    Posts
    373
    Thank you, but it still wont work. Im sure its a problem with the server configuration because the same script works on a different host i have.

    Thank you.

  4. #4
    Join Date
    Nov 2012
    Posts
    14
    Contact your hosting company's tech support and ask if they give your site SMTP access. Not all hosts and/or all accounts do. If they don't, you'll have to ask them to enable it for you. If they don't, you'll have to change hosts.

  5. #5
    Join Date
    Jul 2006
    Posts
    373
    Thanks. So this script needs smtp server to go? i believe i do have, i think its just turned off or something.

  6. #6
    Join Date
    Nov 2012
    Posts
    14
    Quote Originally Posted by supercain View Post
    Thanks. So this script needs smtp server to go?
    Yes.

    i believe i do have, i think its just turned off or something.
    Contact your hosting company. (If it's your own server, your ISP may block emails not sent to their server. Most of them do now.)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles