Solved

Php email form script doesn't work

Posted on 2004-10-21
280 Views
Last Modified: 2011-09-20
I have a php script that i want to use on my site to send an email through a form from the site. But it doesn't work.
The form can be found at http://jordysoft.com/files/contactus.php

Can please someone take a look at the form to see what is wrong.

0
Question by:dia21
    20 Comments
     
    LVL 48

    Expert Comment

    by:hernst42
    To track down the error we need to see the code of sendmail.php. The form looks ok
    0
     

    Author Comment

    by:dia21
    <?php
     $myemail = "jordysoft@yahoo.com";

    if (!isset($userEmail))
    echo "User Ip: $ip" ;

    $todayis = date("l, F j, Y, g:i a") ;

    $subject = "Contact email from Jordysoft.com site" ;

    $message = " $todayis [EST] \n
    Message: $userMessage \n
    From: $userName ($userEmail)\n
    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    ";

    $from = "From: $myemail\r\n";

    if ($myemail != "")
    mail($myemail, $subject, $message, $from);

    ?>

    <b><p align=center>
    Date: <?php echo $todayis ?>
    <br>
    Thank You : <?php echo $userName ?> ( <?php echo $userEmail ?> )
    <br>
    Your IP: <?php echo $ip ?>
    0
     
    LVL 48

    Expert Comment

    by:hernst42
    The script looks okay. Can't see why it is not working.
    you may add a check
    if (!mail($myemail, $subject, $message, $from)) {
       echo "Sending mail failed maybe a safemode-problem?\n";
    }

    If that message apears you php-configuration is not correct for the mail-part
    0
     
    LVL 5

    Expert Comment

    by:basiclife
    Is the SMTP server configured correctly? Is it your own server or someone else's?
    0
     
    LVL 2

    Expert Comment

    by:TheUnkind
    try this


    <?php
     $myemail = "jordysoft@yahoo.com";

    if (!isset($_POST['userEmail']))
    echo "User Ip: $ip" ;

    $todayis = date("l, F j, Y, g:i a") ;

    $subject = "Contact email from Jordysoft.com site" ;

    $message = $todayis."[EST] \n
    Message:". $_POST['userMessage']."\n
    From:". $_POST['userName']."(".$_POST['userName'].")\n
    Additional Info : IP =". $_POST['ip']." \n
    Browser Info:". $_POST['httpagent']." \n
    Referral :". $_POST['httpref']." \n";

    $from = "From: $myemail\r\n";
    echo $message;
    if ($myemail != "")
    mail($myemail, $subject, $message, $from);

    ?>
    0
     
    LVL 2

    Expert Comment

    by:TheUnkind
    one more thing
    change $ip to $_POST['ip']
    0
     
    LVL 2

    Expert Comment

    by:TheUnkind
    my bad... here's the latest

    <?php
     $myemail = "jordysoft@yahoo.com";

    if (!isset($_POST['userEmail']))
    echo "User Ip: ".$_POST['ip'] ;

    $todayis = date("l, F j, Y, g:i a") ;

    $subject = "Contact email from Jordysoft.com site" ;

    $message = $todayis."[EST] \n
    Message:". $_POST['userMessage']."\n
    From:". $_POST['userName']."(".$_POST['userName'].")\n
    Additional Info : IP =". $_POST['ip']." \n
    Browser Info:". $_POST['httpagent']." \n
    Referral :". $_POST['httpref']." \n";

    $from = "From: $myemail\r\n";   /*comment this is supposed to be the sender's email it should be: "From: ".$_POST['userEmail']; */

    if ($myemail != "")
    mail($myemail, $subject, $message, $from);

    ?>
    0
     

    Author Comment

    by:dia21
    hernst42,
    i've put your code i don't get that message.

    basiclife,
    No is not my one server. I'm hosting with hollosite.com (100webspace.com). Here are the server information:

    Operating system :      Debian GNU/Linux      
    Perl Modules :      Click to View (NOTE: this page is over 450 KB)      
    Perl version :      v5.8.4       
    Perl path :      /usr/bin/perl       
    Sendmail path :      /usr/sbin/sendmail       
    MySQL version :      4.0.21-log       
    PHP version :      4.3.4       
    Physical IP address :      70.84.255.131      
    Mysql host :      hollosite.com      
    Mysql port :      3306      
    POP3/IMAP (incoming mail server) :      mail.hollosite.com      
    POP3 port :      110      
    IMAP port :      443      
    SMTP (outgoing mail server) :      mail.hollosite.com      
    SMTP port :      25
    Server type:      Apache


    TheUnkind,
    I've put your code still isn't working. Do i have to put  myemail the email that i set on the server.
    e. g Instead of jordysoft@yahoo.com to put one of the emails xx@jordysoft.com. Does it matter this?

    0
     
    LVL 2

    Expert Comment

    by:TheUnkind
    >I've put your code still isn't working. Do i have to put  myemail the email that i set on the server.
    >e. g Instead of jordysoft@yahoo.com to put one of the emails xx@jordysoft.com. Does it matter this?

    as far as i know at your script it sends the form information to your yahoo.com email account, but if you want it to send to your own site email you can change the myemail to xx@jordysoft.com... May i know where would you want your contact form send the information? to your yahoo account or to the jordysoft account?
    0
     
    LVL 2

    Accepted Solution

    by:
    ok try this, it checks the usermail if empty then it won't do anything but if it has a value it will send the form to jordysoft@yahoo.com, still you need a email checker if the email entered is valid :


    <?php
     $myemail = "jordysoft@yahoo.com"; #change this to xx@jordysoft.com if you want to send it to this email

    if (!empty($_POST['userEmail'])){
      echo "User Ip: ".$_POST['ip'];

      $todayis = date("l, F j, Y, g:i a") ;

      $subject = "Contact email from Jordysoft.com site" ;

    $message = $todayis."[EST] \n
    Message:". $_POST['userMessage']."\n
    From:". $_POST['userName']."(".$_POST['userName'].")\n
    Additional Info : IP =". $_POST['ip']." \n
    Browser Info:". $_POST['httpagent']." \n
    Referral :". $_POST['httpref']." \n";

    $from = "From: $myemail\r\n";

       if (!mail($myemail, $subject, $message, $from)){
          echo "Unable to send email";
       }
    }else{
     echo "Email is empty";
    }
    ?>
    0
     

    Author Comment

    by:dia21
    The email to be sent to yahoo account. I just asked you if it matter the email account.

    i've put your new code but still i don't receive any email into my yahoo account.
    If i leave empty the email address i get "Email is empty" and when i put an email i get no errors but the message i can't receive it.

    Do i have to configure the mail path I've put the mail path in contact page but without any difference.
    Can you take a look at the form page if is ok (if you didn't saw it)

    http://jordysoft.com/files/contactus.php

    I've run out of ideas ofn this:)
    0
     
    LVL 48

    Expert Comment

    by:hernst42
    THe only one thing to track that issue down would be to analyze the logs of the mailserver so you can see where the problem is. Is the mail send by php initial recieived by the mail-server or not. If this is not the case there might be a problem with you mail-settings with in php Can you post a link to a page where the phpinfo can b eview of that server.

    If the mail is received by the mailserver this will be a problem with the mailserver and not with PHP.
    0
     

    Author Comment

    by:dia21
    I don't know were to search/give you the link for the logs. Here is the php configuration (i think) that i saved the file form my account http://jordysoft.com/php.html.

    The site i have is hosted with http://100webspace.com free account. So i can make a new account and put the site on that and give you the username/pass to test it or if you have time maybe can you create a new account and see were is the pb.

    Please help because i really need this to fix because i get for day to day many spam emails and i want to change my emails so i can hide the emails from the public.

    0
     
    LVL 2

    Expert Comment

    by:TheUnkind
    hey chief, i don't think my script has an error, but i guess 100webspace.com are the one who doesn't send an email. i signed up and put up a mail script but it doesn't sent any email to my yahoo account, even to my other mail accounts... if you want i can host it for you, mail me @ amitkronos@yahoo.com. thanks
    0
     
    LVL 2

    Expert Comment

    by:TheUnkind
    i mean hosting your script just to test it =)
    0
     

    Author Comment

    by:dia21
    TheUnkind, i send to you an email and i also send an email to 100webswpace.com about this problem. I wait the response to see if i get a solution of this problem.

    Thanks
    dia21
    0
     
    LVL 5

    Expert Comment

    by:basiclife
    0
     
    LVL 2

    Expert Comment

    by:TheUnkind
    basiclife, im so sorry... if there's a way to delete my email in this post that'll be very good.. Thank you
    0
     
    LVL 5

    Expert Comment

    by:basiclife
    To my knowledge no. Not the end of the world :D I wasn't exactly in a position to solve the problem anyway but it's worth noting for future reference (also, SPAMers can get your email address from here so you might get totally inundated)
    0
     

    Author Comment

    by:dia21
    i received the email from 100webspace.com and they say that disabled this function for security reasons or something lke this. It seems that the script works.

    Thank your for your comments and for your help.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    931 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now