Jump to content

I need help with an email php code


rockero_d

Recommended Posts

Hello guys, this is my first time posting on this forum, so please let me know if I'm on the wrong spot.

Below here I'm writing the form I have on my website and also the PHP code I'm using to send the email.

For some reason it's not working, every time I try to send the email, I always end up returning to my form page, instead of the successfully sent email.

 

Website form:

 

<form id="rsvp" name="rsvp" method="POST" action="message.php">

    <table width="308" border="0">

      <tr>

        <td width="78">Name: *</td>

        <td width="220"><input name="Name" type="text" id="tswname" size="35" /></td>

      </tr>

      <tr>

        <td>Address:</td>

        <td width="220"><textarea name="Address" cols="35" rows="3" id="tswaddress"></textarea></td>

      </tr>

      <tr>

        <td>Email: *</td>

        <td width="220"><input name="Email" type="text" id="tswemail" size="35" /></td>

      </tr>

    </table>

    <p>

      <label>Will you be attending?*

        <input type="Radio" name="Radio" id="tswyes" value="Yes" />

      Yes</label>

       

      <label>

        <input type="Radio" name="Radio" id="tswno" value="No" />

        No</label>

    </p>

    <p>

      <label>Number of Guests *

        <select name="Guests" id="tswguests">

          <option value="0" selected="selected">0</option>

          <option value="1">1</option>

          <option value="2">2</option>

        </select>

      </label>

    </p>

    <p> </p>

    <p>

      <label>

        <input name="Submit" type="submit" id="Submit" value="Submit" />

      </label>

    </p>

    <p>*Necessary fields. </p>

  </form>

 

and this is my PHP file

 

<?php

 

$mailto = '[email protected]' ;

$subject = "Wedding RSVP" ;

 

$formurl = "http://website.com/rsvp.html" ;

$errorurl = "http://website.com/rsvp/error.html" ;

$thankyouurl = "http://website.com/rsvp/confirmation.html" ;

 

$email_is_required = 1;

$name_is_required = 1;

$uself = 0;

$use_envsender = 0;

$use_webmaster_email_for_from = 0;

$use_utf8 = 1;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;

$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;

if (!isset( $use_envsender )) { $use_envsender = 0 ; }

$envsender = "-f$mailto" ;

$name = $_POST['Name'] ;

$address = $_POST['Address'] ;

$email = $_POST['Email'] ;

$rsvp = $_POST['Radio'] ;

$guest = $_POST['Guests'] ;

$http_referrer = getenv( "HTTP_REFERER" );

 

if (!isset($_POST['email'])) {

header( "Location: $formurl" );

exit ;

}

if (($email_is_required && (empty($email) || !ereg("@", $email))) || ($name_is_required && empty($name))) {

header( "Location: $errorurl" );

exit ;

}

if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email )) {

header( "Location: $errorurl" );

exit ;

}

if (empty($email)) {

$email = $mailto ;

}

 

$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;

 

if (get_magic_quotes_gpc()) {

$rsvp = stripslashes( $rsvp );

}

 

$messageproper =

"This message was sent from:\n" .

"$http_referrer\n" .

"------------------------------------------------------------\n" .

"Name of guest: $name\n" .

"Email of guest: $email\n" .

"Address of guest: $address\n" .

"------------------------- RSVP -------------------------\n\n" .

"Attending: $rsvp\n".

"Number of guests: $guest\n".

"\n\n------------------------------------------------------------\n" ;

 

$headers =

"From: \"$name\" <$fromemail>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.13.0" .

$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;

 

if ($use_envsender) {

mail($mailto, $subject, $messageproper, $headers, $envsender );

}

else {

mail($mailto, $subject, $messageproper, $headers );

}

header( "Location: $thankyouurl" );

exit ;

 

?>

 

I've tried everything but is still not working. Thank you for your help in advance.

Link to comment
https://forums.phpfreaks.com/topic/184350-i-need-help-with-an-email-php-code/
Share on other sites

first thing to check is whether u can send mails from your localhost/server.

 

check this out

telnet <server ip address> 25

if it gives some time out or something then it is not working..

or else it is working

then try using a simple mail program and see if it goes then it is happening try to echo the values of the details which u are fetching, i.e $email  and all others..

first check on these..

and let me know

 

Try this script:

 

create the sendmail.php

 

<!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>
</head>
<body>
<form id="feedback" name="feedback" target="buffer" action="process.php" method="post">
From email: <input id="from" type="text" name="from" value="" /><br />
Your name: <input id="ContactName" type="text" name="ContactName" value="" /><br />
E-mail: <input id="ContactMail" type="text" name="ContactMail" value=""/><br />
Subject: <input id="subject" type="text" name="subject" value="mailing php script" /><br />
Message: <textarea name="message">Lorem Ipsum text.</textarea>
<br />
<input type="hidden" name="remote_addr" value="<?=$_SERVER['REMOTE_ADDR']?>" />
<input type="submit" name="submit"  value="submit" />
</form>

<iframe src="process.php" name="buffer" id="buffer" frameborder="0" style="width: 90%; height: 300px;" ></iframe> 

</body>

 

 

create process.php

<pre>
<?

if(!empty($_POST)){



function check_input($data){

$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);

return $data;

}

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_POST['ContactName'] . " <" . $_POST['ContactMail'] . ">";


$from = $_POST['from'];

mail($from, $_POST['subject'], check_input($_POST['message']), $headers);








print <<< eoe

<script type="text/javascript">
<!--


parent.document.getElementById("feedback").innerHTML = "<h1>Mesage sent successfully from {$_POST['remote_addr']}</h1>";


setTimeout('delayedRedirect()', 2000);
function delayedRedirect(){
top.location.replace("{$_SERVER['HTTP_REFERER']}");
}

// -->


</script>


eoe;




}
?>

</pre>

 

run the code

Thanks ym_chaitu, but I'm on a Windows 7 computer and I can't seem to find Telnet... As with the code, I'm gonna try it.

 

Thanks flafaille, I tried your code and the message of sending the email successfully came out, which I assumed was because the message was sent correctly, but I still haven't got anything on my email address.

u need to enable the telnet command in the 7

u can do this using this step by step instructions

http://chaitu09986025424.blog.co.in/2009/12/08/enable-telnet-command-in-windows-7vista/

 

or else u can use this site to see what all ports are open in ur machine/ip

 

http://canyouseeme.org/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.