Forum Moderators: coopster

Message Too Old, No Replies

sending email... please help

         

Flolondon

12:50 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



<?

if (($_POST[sender_name] == "") && ($_POST[sender_address] == "") && ($_POST[sender_number] == "") &&($_POST[message_heading] == "") && ($_POST[message] == "")) {
header ("Location: contactus.html");
exit;


$msg .= "Sender's Name: $_POST[sender_name]\n";
$msg .= "Sender's Adsdress: $_POST[sender_address]\n";
$msg .= "Sender's Number: $_POST[sender_number]\n";
$msg .= "Message Heading: $_POST[sender_heading]\n";
$msg .= "Message: $_POST[message]\n"

$to = "admin@aeasd.com
$subject = Website feedback";
$mailheaders = "From: My Web Site admin@metoday.com
$mailheaders.= "Reply-To: $_POST[sender_email]\n";

mail($to, £subject, $msg, $mailheaders);
?>

<HTML>
<HEAD>
<TITLE>Feedback Form Sent - Thanks </TITLE>
</HEAD>
<BODY>
<H1> The following e-mail has been sent. We will endeavour to get in contact with you as soon as possible </H1>

<P> <strong> Your Name: </strong><br>
<? echo "$_POST [sender_name]";?>

<P> <strong> Your address: </strong><br>
<? echo "$_POST [sender_address]";?>

<P> <strong> Your Number: </strong><br>
<? echo "$_POST [sender_number]";?>

<P> <strong> The Heading: </strong><br>
<? echo "$_POST [message_heading]";?>

<P> <strong> The Heading: </strong><br>
<? echo "$_POST [message_heading]";?>

<P> <strong> The Main Message: </strong><br>
<? echo "$_POST [message]";?>

</BODY>
</HTML>

what have i done wrong please help. i am using php 5 script on a php4 server online.

dcrombie

1:00 pm on Aug 16, 2005 (gmt 0)



£ instead of $?

grandpa

1:03 pm on Aug 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is this a pop quiz?

  • No closing bracket on if.

  • $to = "admin@aeasd.com
    $to = "admin@aeasd.com";

  • $subject = Website feedback";
    $subject = "Website feedback";

  • $mailheaders = "From: My Web Site admin@metoday.com
    $mailheaders = "From: My Web Site admin@metoday.com";

  • £subject
    $subject

    Did I miss any?

  • grandpa

    1:17 pm on Aug 16, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    You might need to change this these lines in order to see your posted values.

    <? echo "$_POST [sender_address]";?>
    to
    <? echo $_POST ['sender_address'];?>

    From habit I always enclose GET and POST variable names with a single quote, $_POST['sender_address'].

    Flolondon

    3:03 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    <?

    if (($_POST[sender_name] == "") && ($_POST[sender_address] == "") && ($_POST[sender_number] == "") &&($_POST[message_heading] == "") && ($_POST[message] == "")) {
    header ("Location: contactus.html");
    exit;


    $message .= "Sender's Name: $_POST[sender_name]\n";
    $message .= "Sender's Address: $_POST[sender_address]\n";
    $message .= "Sender's Number: $_POST[sender_number]\n";
    $message .= "Message Heading: $_POST[sender_heading]\n";
    $message .= "Message: $_POST[message]\n"

    $to = "asdf@yahoo.co.uk";
    $subject = "";
    $message = "";
    $mailheaders = 'To: tim <sonas@yahoo.co.uk>' . "\r\n";
    $mailheaders .= 'cc: uyk <kjhu@yahoo.co.uk>' . "\r\n";
    $mailheaders .='bcc: jo <jkhkj@aol.com> ."\r\n";
    $mailheaders .= 'MIME-Version: 1.0'. \n";
    $mailheaders .= 'Content-type: text/html; charset=iso-8859-1'. \n";

    $sent = mail ( $to, $subject, $message, $mailheaders);

    if($sent) {
    echo 'Your message has been sent.';
    }
    else {
    echo 'There was a problem and your message has not been sent.';
    }


    ?>

    <HTML>
    <HEAD>
    <TITLE>Feedback Form Sent - Thanks </TITLE>
    </HEAD>
    <BODY>
    <H1> The following e-mail has been sent. We will endeavour to get in contact with you as soon as possible </H1>

    <P> <strong> Your Name: </strong><br>
    <? echo $_POST ['sender_name'];?>

    <P> <strong> Your address: </strong><br>
    <? echo $_POST ['sender_address'];?>

    <P> <strong> Your Number: </strong><br>
    <? echo $_POST ['sender_number'];?>

    <P> <strong> The Heading: </strong><br>
    <? echo $_POST ['message_heading'];?>

    <P> <strong> The Heading: </strong><br>
    <? echo $_POST ['message_heading'];?>

    <P> <strong> The Main Message: </strong><br>
    <? echo $_POST ['message'];?>


    </BODY>
    </HTML>
    thank you but i am still having no luck

    Romeo

    3:39 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    Can you, please, give some more details in where your "having no luck" lies exactly?
    Do you see any error messages on the screen? in the httpd's error_log? or no PHP errors but no data in echoing the POST data? no mail? or ...?
    Do you have an empty line before your first '<?'? -- shouldn't be.

    It may be not wrong to apply Grandpa's habits of quoting the POST variables to the first part of your code, too.

    Regards,
    R.

    Flolondon

    3:57 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    br />
    <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>C:\Program Files\EasyPHP1-8\www\contactus.php</b> on line <b>8</b><br />
    <br />
    <b>Parse error</b>: parse error, unexpected T_STRING in <b>C:\Program Files\EasyPHP1-8\www\contactus.php</b> on line <b>8</b><br />

    thanks for replying.. this is what it says..to the above script

    Flolondon

    4:11 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    Frequently Asked Questions
    Enabling PHP: PHP is automatically enabled on all accounts.

    Hosting platform: Windows, Win32

    Path to web root: D:\\wwwsites\\yoursitecom\\www or use single forward slashes D:/wwwsites/yoursitecom/www
    Path to ftp root: D:\\wwwsites\\yoursitecom or use single forward slashes D:/wwwsites/yoursitecom
    Path to odbc folder: D:\\wwwsites\\yoursitecom\\odbc or use single forward slashes D:/wwwsites/yoursitecom/odbc

    PHP version: 4.3.x
    Safe mode: On
    ASP style tags: On
    Open_basedir: D:/wwwsites Note - the open base directory is further limited to the ftp root and everything below by file system permissions.
    Upload_max_filesize: 5 MB

    PHP And Email
    Outgoing mail server: The outgoing mail server for your web application is 127.0.0.1

    PHP Mail() function: The PHP Mail() function operates differently than expected on a Windows server. On a Windows server, we must use the ini_set() function to set the sendmail_from parameter in our PHP scripts or applications.

    Format
    ini_set("sendmail_from", "yourEmailAddress@YourDomain.com");
    mail($send_to_address, $subject, $body);

    Example
    <?php

    ini_set("sendmail_from", "yourEmailAddress@YourDomain.com");

    mail("account@server.com","testing mail on win32 via php","Test to make sure that mail is configured correctly.");

    ?>

    just copied and pasted information from a hosting company.. apparently the hosting company is using a windows server and therefore i believe things would need to be a bit different

    sned

    5:08 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    In these lines:

    $message = "Sender's Name: $_POST[sender_name] "\r\n";
    $message .= "Sender's Address: $_POST[sender_address] "\r\n";
    $message .= "Sender's Number: $_POST[sender_number] "\r\n";
    $message .= "Message Heading: $_POST[sender_heading] "\r\n";
    $message .= "Message: $_POST[message] "\r\n";

    the " don't match up right ... try something like:

    <edit>added ' into the post variable</edit>

    $message = "Sender's Name:" . $_POST['sender_name'] . "\r\n";
    $message .= "Sender's Address:" . $_POST['sender_address'] . "\r\n";
    $message .= "Sender's Number:" . $_POST['sender_number'] . "\r\n";
    $message .= "Message Heading:" . $_POST['sender_heading'] . "\r\n";
    $message .= "Message:" . $_POST['message'] . "\r\n";

    Also, here:

    $mailheaders .= 'Browser: $HTTP_USER_AGENT\n';
    $mailheaders .='From page: $HTTP_HOST\n';
    $mailheadersv .='IP address: $SERVER_ADDR\n';

    all those lines need to be enclosed in double quotes (") otherwise those variables won't be parsed.

    $mailheaders .= "Browser: $HTTP_USER_AGENT\n";
    $mailheaders .= "From page: $HTTP_HOST\n";
    $mailheadersv .= "IP address: $SERVER_ADDR\n";

    (I'm guessing that the 'v' on the end is a typo).

    I think that will help things out a bit.

    -sned

    [edited by: sned at 5:11 pm (utc) on Aug. 16, 2005]

    baze22

    5:08 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    Looks like a syntax error:

    $message = "Sender's Name: $_POST[sender_name] "\r\n";

    should be:

    $message = "Sender's Name:" . $_POST[sender_name] . "\r\n";

    baze

    ChadSEO

    5:09 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    Flolondon,

    I looks like you have an extra double quote on several lines:

    $message = "Sender's Name: $_POST[sender_name] "\r\n";
    $message .= "Sender's Address: $_POST[sender_address] "\r\n";
    $message .= "Sender's Number: $_POST[sender_number] "\r\n";
    $message .= "Message Heading: $_POST[sender_heading] "\r\n";
    $message .= "Message: $_POST[message] "\r\n";

    Remove the second double quote, right before the \r\n, and I think that should fix it.

    Chad

    Flolondon

    5:21 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    thanks and now its saying this..lol

    $mailheaders .= 'MIME-Version: 1.0'. "\r\n";
    $mailheaders .= 'Content-type: text/html; charset=iso-8859-1'. "\r\n";

    <br />
    <b>Parse error</b>: parse error, unexpected T_STRING in <b>C:\Program Files\EasyPHP1-8\www\contactus.php</b> on line <b>27 (in this case line one here)</b><br />

    with the error message

    sned

    5:46 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    I also found this later on :

    $mailheaders .='bcc: jo <jkhkj@aol.com> . "\r\n";

    This should be:

    $mailheaders .='bcc: jo <jkhkj@aol.com>' . "\r\n";

    That might fix your later error .. I don't know.

    -sned

    jatar_k

    5:46 pm on Aug 16, 2005 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    if you keep making new threads the members who are trying to help will miss them and think they are resolved and members viewing it for the first time will not know the history of the conversation.

    I spliced the 3 together they look fairly contiguous

    Flolondon

    6:14 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member





    <?

    if (($_POST[sender_name] == "") && ($_POST[sender_address] == "") && ($_POST[sender_number] == "") &&($_POST[message_heading] == "") && ($_POST[message] == "")) {
    header ("Location: contactus.html");
    exit;

    $message = "Sender's Name:" . $_POST['sender_name'] . "\r\n";
    $message .= "Sender's Address:" . $_POST['sender_address'] . "\r\n";
    $message .= "Sender's Number:" . $_POST['sender_number'] . "\r\n";
    $message .= "Message Heading:" . $_POST['sender_heading'] . "\r\n";
    $message .= "Message:" . $_POST['message'] . "\r\n";



    $to = "asdf@yahoo.co.uk";
    $subject = "";
    $message = "";
    $thankyou = "http://www.jhkj.com/thankyou.html";
    $mailheaders = 'To: tim <sonas@yahoo.co.uk>' . "\r\n";
    $mailheaders .= 'cc: uyk <kjhu@yahoo.co.uk>' . "\r\n";
    $mailheaders .='bcc: jo <jkhkj@aol.com>' ."\r\n";
    $mailheaders .= "Browser: $HTTP_USER_AGENT\n";
    $mailheaders .= "From page: $HTTP_HOST\n";
    $mailheaders .= "IP address: $SERVER_ADDR\n";
    $mailheaders .= "MIME-Version: 1.0 \r\n";
    $mailheaders .= "Content-type: text/html; charset=iso-8859-1 \r\n";

    $sent = mail ( $to, $subject, $message, $mailheaders);
    Header ("Location: $thankyou");

    if($sent) {
    echo 'Your message has been sent.';
    }
    else {
    echo 'There was a problem and your message has not been sent.';
    }


    ?>

    <HTML>
    <HEAD>
    <TITLE>Feedback Form Sent - Thanks </TITLE>
    </HEAD>
    <BODY>
    <H1> The following e-mail has been sent. We will endeavour to get in contact with you as soon as possible </H1>

    <P> <strong> Your Name: </strong><br>
    <? echo $_POST ['sender_name'];?>

    <P> <strong> Your address: </strong><br>
    <? echo $_POST ['sender_address'];?>

    <P> <strong> Your Number: </strong><br>
    <? echo $_POST ['sender_number'];?>

    <P> <strong> The Heading: </strong><br>
    <? echo $_POST ['message_heading'];?>

    <P> <strong> The Heading: </strong><br>
    <? echo $_POST ['message_heading'];?>

    <P> <strong> The Main Message: </strong><br>
    <? echo $_POST ['message'];?>


    </BODY>
    </HTML>

    <br />
    <b>Parse error</b>: parse error, unexpected $ in <b>C:\Program Files\EasyPHP1-8\www\contactus.php</b> on line <b>74</b><br />

    which is well passed the </HTML> message..

    and now it is giving me this message..

    sned

    6:24 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    As grandpa pointed out earlier on:

    if (($_POST[sender_name] == "") && ($_POST[sender_address] == "") && ($_POST[sender_number] == "") &&($_POST[message_heading] == "") && ($_POST[message] == "")) {
    header ("Location: contactus.html");
    exit;

    There needs to be a '}' after exit;

    -sned

    /em blows the wisp of smoke from the barrel :)

    [edited by: sned at 6:26 pm (utc) on Aug. 16, 2005]

    jatar_k

    6:24 pm on Aug 16, 2005 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    your first line is wrong

    you have an opening brace but no closing and all those parentheses don't need to be there, change first 4 lines to this

    if ($_POST[sender_name] == "" && $_POST[sender_address] == "" && $_POST[sender_number] == "" && $_POST[message_heading] == "" && $_POST[message] == "") {
    header ("Location: contactus.html");
    exit;
    }

    <added>sned was quicker ;)

    Flolondon

    7:04 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    Please help

    if (($_POST[sender_name] == "") && ($_POST[sender_address] == "") && ($_POST[sender_number] == "") &&($_POST[message_heading] == "") && ($_POST[message] == "")) {
    exit; }

    Notice: Use of undefined constant sender_name - assumed 'sender_name' in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Undefined index: sender_name in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Use of undefined constant sender_address - assumed 'sender_address' in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Undefined index: sender_address in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Use of undefined constant sender_number - assumed 'sender_number' in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Undefined index: sender_number in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Use of undefined constant message_heading - assumed 'message_heading' in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Undefined index: message_heading in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Use of undefined constant message - assumed 'message' in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    Notice: Undefined index: message in c:\program files\easyphp1-8\www\tmpe50cllbwx1.php on line 5

    sned

    7:08 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    if ($_POST[sender_name] == "" && $_POST[sender_address] == "" && $_POST[sender_number] == "" && $_POST[message_heading] == "" && $_POST[message] == "") {
    header ("Location: contactus.html");
    exit;
    }

    guess I just overlooked it ... all the $_POST variables need to be in single quotes:

    if ($_POST['sender_name'] == "" && $_POST['sender_address'] == "" && $_POST['sender_number'] == "" && $_POST['message_heading'] == "" && $_POST['message'] == "") {
    header ("Location: contactus.html");
    exit;
    }

    -sned

    <edit>bah .. can't even count my own '</edit>

    Flolondon

    7:16 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    if (($_POST['sender_name'] == "") && ($_POST['sender_address'] == "") && ($_POST['sender_number'] == "") &&($_POST['message_heading'] == "") && ($_POST['message'] == "")) {
    exit; }

    Notice: Undefined index: sender_name in c:\program files\easyphp1-8\www\tmpekj2ilbxh5.php on line 5

    Notice: Undefined index: sender_address in c:\program files\easyphp1-8\www\tmpekj2ilbxh5.php on line 5

    Notice: Undefined index: sender_number in c:\program files\easyphp1-8\www\tmpekj2ilbxh5.php on line 5

    Notice: Undefined index: message_heading in c:\program files\easyphp1-8\www\tmpekj2ilbxh5.php on line 5

    Notice: Undefined index: message in c:\program files\easyphp1-8\www\tmpekj2ilbxh5.php on line 5

    Thanks i have put the single quotes in but still i get these errors... please help

    dmorison

    7:23 pm on Aug 16, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    They're not errors, just a very high level warning that various array keys are not set (which is exactly what you're testing for).

    You need to turn error reporting down a bit in php.ini - here's the docs:

    [uk2.php.net...]

    error_reporting = E_ALL & ~E_NOTICE

    ...seems to be the norm, which will dispose of all those index not set warnings...

    Flolondon

    7:32 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    thanks for your message but i do still need help as when i upload to the server online. i still get those errors. please help

    Flolondon

    7:34 pm on Aug 16, 2005 (gmt 0)

    10+ Year Member



    the thing is i have used the ftp to upload several files to the website and i cannot see any php coding efforts displayed.. when the htm actions itself to the php... all i can see is a blank page

    grandpa

    5:27 am on Aug 17, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    You will see a blank page when this script is started. The reason can be found in your first line, where you are testing all the the post variables for an empty status.


    if (($_POST['sender_name'] == "") && ($_POST['sender_address'] == "") && ($_POST['sender_number'] == "") &&($_POST['message_heading'] == "") && ($_POST['message'] == "")) {
    exit; }

    When the script is run, all of those variables are empty, since nothing was posted. The next line of your script calls the exit function. The script exits, nothing else runs and nothing else is displayed. If you were to add a line just before your exit, say, echo "Hello World";, then you would see that output.

    So, while the script is now debugged and running normally, the result is not what you were expecting. If someone else doesn't do it first, I might be able to re-write this script sometime tonight and post it here for you. Got a couple of bugs to fix over here first...

    Flolondon

    8:39 am on Aug 17, 2005 (gmt 0)

    10+ Year Member



    thanks for your reply but i was using the form to put some information in, i would have thought that the form variables would have been actioned to the php... Do you always need to put something there to see the script on the php rather than using the form

    thanks... hope to hear from your reply.

    grandpa

    12:04 pm on Aug 17, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    Errr. Opps. I forgot that you had a header to redirect the page... so what I said earlier about the page being blank is misleading.

    So you are posting from the form now and nothing is happening? Is the e-mail getting sent? Have you checked the script to ensure that your variables are getting posted? A line of code like this at the top of your script will show you if the form submitted OK.

    foreach ($_POST as $key=>$val) echo $val;

    And, what about your server logs? There might be an error getting logged that will help you understand what is happening.

    Flolondon

    5:17 am on Aug 18, 2005 (gmt 0)

    10+ Year Member



    thanks for your support all..

    but grandpa..i would be grateful for a correct script for emailing php through html forms as i am still having problems.

    thanks..

    grandpa

    4:03 pm on Aug 21, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    I'm going to resurrect this thread one more time.

    I had reworked this original script into a single php script that contained both the form and the form processing. However, when the script is executed in ZEND it always returned a Notice level warning about undefined indexes on this line:

    if (($_POST['sender_name'] == "") ¦¦ ($_POST['sender_address'] == "") ¦¦ ($_POST['sender_number'] == "") ¦¦ ($_POST['message_heading'] == "") ¦¦ ($_POST['message'] == ""))

    Running the same script with no Error Reporting in my own production PHP environment there were no notices or warnings. Inserting the line error_reporting(OFF); did not help in the ZEND environment.

    My question then is why? Is the error reporting a global setting in ZEND, as opposed to per script like I'm familiar with?

    Anyway, to overcome the problem I simply reverted back to the original script format which was a form in the html document and a php script to process the form. (Still awaiting word on how things went.)