1 Attachment(s)
[RESOLVED] How to email from WEBpage?
Dear Friends,
I have built a website with a Page named Contact.html, here the viewer will enter all his data Like
Name |__________|
Email |__________|
Sub: |___________|
Msg |______________________________________________________|
| Submit| < when he clicks the Submit button the msg will be mailed to the email address mentioned already in the Contact.html page.
I tried a lot of combinations, but failed..Can you guys help me ?
Thanks
Rahul
Re: How to email from WEBpage?
PHP has to be run through a web server or else it won't be interpreted. I'm guessing you're just trying to link to the PHP page in the form's action.
For example: The URL will have to be http://servername/page and note file://c:/page. If you don't even have a web server, then you need something like Xampp.
Re: How to email from WEBpage?
Dear Peejavery,
Thanks for replying , I dont have the faintest idea how to mail from webpage,
I just googled some forms downloaded them & tried but failed.
I have a website http://www.cormed.co.in , there I have this Contactfrm.html & email_form.php files , I just did whatever was mentioned in that page how to do it.
But nothing worked out it only says You mail is sent successfully , we will contact you later.( This is a string already inserted at the page it self.!!
Please tell me the steps in order so I can make it work
Thank you once again
Rahul
Re: How to email from WEBpage?
PHP's mail() function will not return an error to the PHP console. That's why it says it's successful. And since you have no idea what I'm talking about concerning PHP...you need to contact the server admins of that domain.
1 Attachment(s)
Re: How to email from WEBpage?
Dear PeejAvery,
After much fiddling with all this stuff, I am completely lost.I am attaching the Contact.html page to you please rectify the problem & send back.The Server Company says , their side is OK, but i have some errors in the code.
Re: How to email from WEBpage?
I've already told you...it has nothing to do with client-side HTML. Do some research! This will help you.
http://www.w3schools.com/php/php_mail.asp
Re: How to email from WEBpage?
Dear PeejAvery,
The More I see the braces "}" I get more confused & dizzy..Lets comeback to normal html email sending page, Which I have uploaded to you yesterday.
Please see the mistake & let me know.
The Domain people are saying ,that their side is OK, but I might have some Coding problems(Although I did not Code it !;) ) Please rectify the page & send back , I will have it working :)
Thanks
Rahul
Re: How to email from WEBpage?
I already told you...you cannot do it with HTML. And, if you aren't willing to use PHP...then quite simply you cannot have a mailer.
Re: How to email from WEBpage?
Dear PeejAvery,
Ok , I surrender to you.!! Please help me with the Contact.php page..Give me steps like 1.do this
2. do this... like so....
I know i can not learn PHP in a day..You have to help me Buddy.
Thanks
Rahul
1 Attachment(s)
Re: How to email from WEBpage?
Anyway PeejAvery,
I did some research ,& come up with these two files..Made by me one work Properly but the other says "error" & the mail is not sent.Pls check them & let me know
Thank you
Rahul
Re: How to email from WEBpage?
The very first line of contact.php needs to be removed. There is no PHP on that page at all...so you wouldn't open a PHP tag (and it's invalid anyway).
In your send_contact.php file...
- $from address as listed as a posted variable. Make it plain text. It isn't from the POST data in the form.
- $from_name has a space in the $_POST variable call
- $body is empty...so the e-mail won't have any text
Re: How to email from WEBpage?
Dear PeejAvery,
But the Contact.php shows all the boxes & msgbox properly along with submit button.
I can not use it???? !!!
/q $body is empty...so the e-mail won't have any text /q>
What has to be done in the $body part?
Thanks
Rahul
Re: How to email from WEBpage?
Quote:
Originally Posted by
dsrahul
Dear PeejAvery,
But the Contact.php shows all the boxes & msgbox properly along with submit button.
I can not use it???? !!!
I never said that at all. Do you honestly never read the posts?
Quote:
Originally Posted by
dsrahul
$body is empty...so the e-mail won't have any text
What has to be done in the $body part?
Opposite of empty = fill. So...fill the variable with text!
In the past I have given up on you simply because you put no effort into your work at all. You expect everyone else to do everything for you. That is not why CodeGuru exists! So...here is a completely functional example of PHP mailer (which I have already linked too as well). If you cannot figure it out from this...then you need to research and learn.
mailer.php (You only need 1 file...not two)
PHP Code:
<html>
<body>
<?php
if (isset($_POST['email'])) {
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;
if (mail("your_email_address@domain.com", $subject, $message, "From:" . $email)) {
echo 'E-mail sent';
}
}
else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Email: <input type="text" name="email" /><br />
Subject: <input type="text" name="subject" /><br />
Message:<br />
<textarea name="message" cols="40" rows="15"></textarea><br />
<input type="submit" value="Send" />
</form>
<?php } ?>
</body>
</html>
Re: How to email from WEBpage?
Dear PeejAvery,
Thank you so much, You are a real friend.I am eager to learn, the Books , confuse me. Programmers like you, they know the subject well, I can always learn from them, but when you need to learn from them, they are either offline or they do not reply. The problem with me is , I learn the first line, then When i Study the 2nd line, I forget the first line., after a few days I forget the whole thing.have pity on me.
Anyway I am now trying the thing with your code.If anything comes across, can I seek help from you :) ?
Thanks & Regards
Rahul
Re: How to email from WEBpage?
Dear PeejAvery,
I modified your code ,only the part where I need to input "contactus@cormed.co.in" (My Domain ),
Uploaded the file clicked on Contact Page , The Boxes appeared, Then I filled up the boxes,Clicked submit.
The page became white.No Error Message, No "Your mail is sent".
& the Mail was also not seen in the inbox of contactus@cormed.co.in !!!
Please help
I have tried with Validation also See:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<body>
<?php
if (isset($_POST['email'])) {
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;
if (mail('contactus@cormed.co.in', $subject, $message, "From:" . $email)) {
echo 'Your E-mail has been sent.';
}
}
else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Email: <input type="text" name="email" /><br />
Subject: <input type="text" name="subject" /><br />
Message:<br />
<textarea name="message" cols="40" rows="15"></textarea><br />
<input type="submit" value="Send" />
</form>
<?php } ?>
</body>
</html>
Re: How to email from WEBpage?
The code is 100% correct. At this point, you need to contact the server admins of your domain.
Re: How to email from WEBpage?
The admin says : Solution This is in reference to your query we would like to inform you that all general permissions have been granted at our end.Kindly recompile your pages,check coding errors and bring the modifications accordingly.Do contact us for further assistance.
http://www.cormed.co.in
Re: How to email from WEBpage?
Dear PeejAvery,
What could be wrong in this ?
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<body>
<?php
if (isset($_POST['email'])) {
$email = $_POST['email'] ;
if (!$_POST['email'])
// if not, add that error to our array
$errors[] = "email is required";
$subject = $_POST['subject'] ;
if (!$_POST['Subject'])
// if not, add that error to our array
$errors[] = "Subject is required";
$message = $_POST['message'] ;
if (!$_POST['Message'])
// if not, add that error to our array
$errors[] = "Message body is required";
//Myline
// initialize a variable to
// put any errors we encounter into an array
$errors = array();
// test to see if the form was actually
// posted from our form
$page = $_SERVER['http://www.cormed.co.in'].$_SERVER['PHP_SELF'];
if (!ereg($page, $_SERVER['HTTP_REFERER']))
$errors[] = "Invalid referer\n";
// if there are any errors, display them
if (count($errors)>0){
echo "<strong>ERROR:<br>\n";
foreach($errors as $err)
echo "$err<br>\n";
} else {
// no errors, so we build our message
$recipient = 'contactus@cormed.co.in';
$subject = stripslashes($_POST['Subject']);
$msg = "Message sent by $from\n
".stripslashes($_POST['Message']);
if (mail($recipient,$subject,$message))
echo "Thanks for your message!";
else
echo "An unknown error occurred.";
}
if (mail('contactus@cormed.co.in', $subject, $message, "From:" . $email)) {
echo 'Your E-mail has been sent.';
}
}
else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Email: <input type="text" name="email" /><br />
Subject: <input type="text" name="subject" /><br />
Message:<br />
<textarea name="message" cols="40" rows="15"></textarea><br />
<input type="submit" value="Send" />
</form>
<?php } ?>
</body>
</html>
Re: How to email from WEBpage?
Read this very carefully...there are no errors that would keep the e-mail from being sent. As I've already told you!
Apparently, you're server admins know nothing either...PHP is not a compiled language. Are you sure that your host uses PHP and that it can send mail? That is what you need to discuss with your server admins.
BUT you have errors in your thought process.
- It's 1 form, therefore if it sends, then all those variables are set. Using "if" in that way won't help. Use "if" empty($variable) instead.
- stripslashes should only be used if your server has magic quotes configuration turned on. Check that first. See this link for that info.
Re: How to email from WEBpage?
Quote:
Read this very carefully...there are no errors that would keep the e-mail from being sent. As I've already told you!
Apparently, you're server admins know nothing either...PHP is not a compiled language. Are you sure that your host uses PHP and that it can send mail? That is what you need to discuss with your server admins.
( You are 100% Correct ,They even told me that just use notepad & type like this : Name :<Keep Blank> Email:<Keep Blank> Message: Keep Blank> And compile it.I asked them do they have a PHP Server.They said we have everything, I asked them Is My Server a PHP one? They said maybe.
Then I did a PHP query " <?php phpinfo(); ?>" This PHP file showed me that they are using PHP in my server. I have written them atleast 20 mails to sort this out, they replied a few & then became total silent, Brother,This is Our India.!! <
Quote:
BUT you have errors in your thought process.
No ,Absolutely not, I don't have any doubts about you or your Programming.
Quote:
It's 1 form, therefore if it sends, then all those variables are set. Using "if" in that way won't help. Use "if" empty($variable) instead.
stripslashes should only be used if your server has magic quotes configuration turned on. Check that first. See this link for that info.
So , I have to remove Stripslash part. Let me try again then. But I Know very well that the problem is not on our part ,It is definitely their issue. Either way ,I am at a loss coz I can not send mails !!! [/B]
Ps: I have tried the process they said......What do you think? Yeah it returned the text Only nothing more.
Did you try the contact page at http://www.cormed.co.in.?
Thanks
Rahul
Re: How to email from WEBpage?
Dear PeejAvery,
You are really a genius. I do appreciate that.I dug deep with my little knowledge & the Links you provided me. & found out that .
1. It does not say mail received from dsrahul@gmail com the mail is now being sent but with unknown sender. Mail from : dsrahul@gmail.com not shown instead Unknown Sender is shown.Maximum times dsrahul mails are not received by the Mailbox.
2. It accepts mail from contactus@cormed.co.in and admin@cormed.co.in .The whole message is received without the subject line, in this case it shows the from heading as contactus@cormed.co.in.
3.Is there a way that this mail contactus@cormed.co.in will be static & hidden and another email(customer email) will be shown in the Message part?
I mean :
if (isset($_POST[''])) {
$email = $_POST['email'] ;
if (!$_POST['contactus@cormed.co.in'])
$errors[] = "Email is required"; < this part remains hidden in the code < from email.
if here we write $emailcust = $emailc
Possible ?
Please help
Thanks
Rahul
Re: How to email from WEBpage?
After doing much of Permutation & Combination & research I ended up in this , Which is working perfectly alright.
This is the PHPcode for Contact_process.php
Code:
<?php
/*
*/
// ------- three variables you MUST change below -------------------------------------------------------
$replyemail="contactus@yourwebsite.com"; //change to your email address
$valid_ref1="http://www.yourwebsite.com/form.html"; //change to your domain name
$valid_ref2="http://www.yourwebsite.com/form.html"; //change to your domain name
// -------- No changes required below here -------------------------------------------------------------
//
// email variable not set - load $valid_ref1 page
if (!isset($_POST['email']))
{
echo "<script language=\"JavaScript\"><!--\n ";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}
$ref_page=$_SERVER["HTTP_REFERER"];
$valid_referrer=0;
if($ref_page==$valid_ref1) $valid_referrer=1;
elseif($ref_page==$valid_ref2) $valid_referrer=1;
if((!$valid_referrer) OR ($_POST["block_spam_bots"]!=12))//you can change this but remember to change it in the contact form too
{
echo '<h2>ERROR - not sent.';
if (file_exists("debug.flag")) echo '<hr>"$valid_ref1" and "$valid_ref2" are incorrect within the file:<br>
contact_process.php <br><br>On your system these should be set to: <blockquote>
$valid_ref1="'.str_replace("www.","",$ref_page).'"; <br>
$valid_ref2="'.$ref_page.'";
</blockquote></h2>
: contact_process.php <br> (.)';
exit;
}
//check user input for possible header injection attempts!
function is_forbidden($str,$check_all_patterns = true)
{
$patterns[0] = '/content-type:/';
$patterns[1] = '/mime-version/';
$patterns[2] = '/multipart/';
$patterns[3] = '/Content-Transfer-Encoding/';
$patterns[4] = '/to:/';
$patterns[5] = '/cc:/';
$patterns[6] = '/bcc:/';
$forbidden = 0;
for ($i=0; $i<count($patterns); $i++)
{
$forbidden = preg_match($patterns[$i], strtolower($str));
if ($forbidden) break;
}
//check for line breaks if checking all patterns
if ($check_all_patterns AND !$forbidden) $forbidden = preg_match("/(%0a|%0d|\\n+|\\r+)/i", $str);
if ($forbidden)
{
echo "<font color=red><center><h3>STOP! Message not sent.</font></h3><br><b>
The text you entered is forbidden, it includes one or more of the following:
<br><textarea rows=9 cols=25>";
foreach ($patterns as $key => $value) echo trim($value,"/")."\n";
echo "\\n\n\\r</textarea><br>Click back on your browser, remove the above characters and try again.
</b><br><br><br><br>Secure Connection By :
<a href=\"http://www.yourwebsite.com/\">http://www.yourwebsite.com/</a>";
exit();
}
}
foreach ($_REQUEST as $key => $value) //check all input
{
if ($key == "themessage") is_forbidden($value, false); //check input except for line breaks
else is_forbidden($value);//check all
}
$name = $_POST["name"];
$email = $_POST["email"];
$thesubject = $_POST["thesubject"];
$themessage = $_POST["themessage"];
$success_sent_msg='<font color=red><center><h3>Success! Message sent.</font></h3><br><b>
<p align="center"><strong> </strong></p>
<font color=blue><p align="center"><h3><strong>Your message has been successfully sent to us</font></h3><br><b>
<font color=green><h3></strong> and we will reply as soon as possible.</font></h3><br><b></p>
<font color=magenta><h3><p align="center">A copy of your query has been sent to you.</font></h3><br><b></p>
<font color=black><h3><p align="center">Thank you for contacting us.</font></h3><br><b></p>';
$replymessage = "Hi $name
Thank you for your email.
We will endeavour to reply to you shortly.
Please DO NOT reply to this email.
Below is a copy of the message you submitted:
--------------------------------------------------
Subject: $thesubject
Query:
$themessage
--------------------------------------------------
Thank you";
$themessage = "name: $name \nQuery: $themessage";
mail("$replyemail",
"$thesubject",
"$themessage",
"From: $email\nReply-To: $email");
mail("$email",
"Receipt: $thesubject",
"$replymessage",
"From: $replyemail\nReply-To: $replyemail");
echo $success_sent_msg;
/*
*/
?>
Next this is the Form.html
Code:
<html>
<head>
<title> - - anything.
mailers)</title>
<style>
BODY{color:#000000; font-size: 8pt; font-family: Verdana}
.button {background-color: rgb(128,128,128); color:#ffffff; font-size: 8pt;}
.inputc {font-size: 8pt;}
.style3 {font-size: xx-small}
</style>
</head>
<body>
<form name="phpformmailer" action="contact_process.php" align="center" method="post">
<div align="center"><center><table bgcolor="#F2F2F2" width="742" cellspacing="6">
<tr>
<td width="162"><strong>Contact Us</strong></td>
<td width="556"><span class="style3">Secure Method: <a
href="http://www.yourwebsite.com" title="Your Brand name.">Your Brand name.</a></span></td>
</tr>
<tr>
<td align="right" width="162"><small>Your name:</small></td>
<td width="556"><font face="Arial">
<input class="inputc" size="50" name="name">
<input type="hidden" name="block_spam_bots" value="1">
</font></td>
</tr>
<tr>
<td align="right" width="162"><font color="#000080" size="1">*</font><small> Your email
address:</small></td>
<td align="left" width="556"><font face="Arial"><input class="inputc" size="50"
name="email">
</font></td>
</tr>
<tr align="middle">
<td align="right" width="162"><font color="#000080" size="1">*</font><small> Confirm email
address:</small></td>
<td width="556" align="left"><font face="Arial"><input class="inputc" size="50"
name="email2">
</font></td>
</tr>
<tr>
<td align="right" width="162"><font color="#000080" size="1">*</font><small> Subject:</small></td>
<td width="556"><font face="Arial"><input class="inputc" size="60" name="thesubject">
</font></td>
</tr>
<tr>
<td align="right" width="162">
<p><font color="#000080" size="1">*</font><small> Your
request or query:</small></td>
<td width="556"><textarea style="FONT-SIZE: 10pt" name="themessage" rows="7" cols="60"></textarea>
<a href="http://www.yourwebsite.com"> </a></td>
</tr>
<tr>
<td width="162"></td>
<td width="556"><p>
<input type="button" class="button"
value="Post This Message." name="B1" ONCLICK="javascript:validateForm()">
<small> <small>You must fill in
the fields marked with a *</p>
</td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span class="style3">Protected by: <a
href="http://www.yourwebsite.com" title="Your Brand name">Your Brand name</a></span></p>
</center></div>
</form>
<script language="JavaScript"><!--
function validateForm()
{
var okSoFar=true
with (document.phpformmailer)
{
var foundAt = email.value.indexOf("@",0)
if (foundAt < 1 && okSoFar)
{
okSoFar = false
alert ("Please enter a valid email address.")
email.focus()
}
var e1 = email.value
var e2 = email2.value
if (!(e1==e2) && okSoFar)
{
okSoFar = false
alert ("Email addresses you entered do not match. Please re-enter.")
email.focus()
}
if (thesubject.value=="" && okSoFar)
{
okSoFar=false
alert("Please enter the subject.")
thesubject.focus()
}
if (themessage.value=="" && okSoFar)
{
okSoFar=false
alert("Please enter the details for your enquiry.")
themessage.focus()
}
if (okSoFar==true)
{
block_spam_bots.value=4*3;//spam bots currently can not read JavaScript, if could then they'd fail the maths!
submit(); // do check for updatea often at:
}
}
}
// --></script>
</body>
</html>
this works perfectly alright.
Re: How to email from WEBpage?
My Sincerest Thanks to PeejAvery, who guided me like a Friend & teacher.
I have posted the code to enable all of us who can not find a way out & have to seek help or request others to do their job.
I do not know if I have violated the codeguru rules.If so I would request Brad to remove this post.
Thank you PeejAvery, You are always my best buddy.
Thanks
Rahul
[Resolved]