Follow Fantora on Twitter
Fantora Word of Classified Ads and Community Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

sending email with php

Options
hari
Posted: Tuesday, December 23, 2008 7:31:09 AM
Rank: Advanced Member
Groups: Member

Joined: 3/31/2008
Posts: 113
Points: 339
Location: London

sending email with php

can any body guide me of sending email with php?
manzor
Posted: Tuesday, December 23, 2008 7:35:37 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2008
Posts: 39
Points: 117
Location: GB

sending email with php

hari wrote:
can any body guide me of sending email with php?


in PHP is the field names for the information you are gathering. "From" will be converted into a variable with the same name by php (it would become $from), the "subject" will be made into $subject and the "contents" of the message will be made into $contents. For submitting the actual form, we will activate the php script by using the form action tag and linking to send_mail.php3:

Code:
<form action="send_email.php3" method="POST">


The $to variable will be defined in the send_mail.php3 script to point to my email address (you'll see the php code momentarily), of course. I also prefill the subject with the words "diary entry suggestion" which visitors can change to something else, if they want:

Code:
<input type="text" size="22" name="subject" value="diary entry suggestion">


Ok, let's take a look at the code to mail the contents of the above form to me and if the process is successful it will redirect you right back to this page. In order for this code to work you will need to know the path to sendmail on your server.

Code:
<?
$to = "webmaster@php-scripts.com";
$from_header = "From: $from";
if($contents != "")
{
   //send mail - $subject & $contents come from surfer input
   mail($to, $subject, $contents, $from_header);
   // redirect back to url visitor came from
   header("Location: $HTTP_REFERER");
}
  else
{
   print("<HTML><BODY>Error, no comments were submitted!");
   print("</BODY></HTML>");
}
?>


Notes: I make sure there are some comments submitted or else show an error message by using the != (not equal) with an if statement. When you want to redirect the browser using the header function (like when using the setcookie function) you must do it before any HTML. With the header and $HTTP_REFERER in the code above I am simply sending people who submit the form back where they came from, which should will be this page that calls the form. I could have easily changed the header line to read:

Code:
header("Location: thankyou.html");


And at a page named thankyou.html I could have thanked them for submitting the form.
Users browsing this topic
Guest

 Related
PHP and seo
Boonex Dolphin PHP script is SCAM!!!
Problem in fetching rows from mysql in php?
remommendations for PHP math CAPTCHA script please
avoid php pages getting hacked
sending email with php
Powerful user administration application
please suggest
updating in MySQL
problem with .htaccess
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Fantora Blog | Discount Shop UK | Discount Shop USA | Discount Shop Canada | Discount Boutique France | Discount Shop Deutschland | Discount Shop Italia | Descuento Shop España

Free Classified ads, Webmaster Forum & Technology Reviews | Fantora Free Classified Ads | Buy & Sell Electronics, Mobile phones & Accessories | fantora Forums Community | Buy & Sell DVD, Games and Consols | Free eBooks & Softwares | SEO & Affiliate Marketing Discussion | Programming Language Forum (.NET, ASP, PHP, SQL) | Free Classified Ads | General Stuff (Movies, Chat, Comics) | Free Online English Movies & Reviews | Free Online Hindi Movies & Reviews | Australia & New Zealand Immigration Forum | Europe immigration forum | Canada Immigration Forum | Ireland Immigration Forum | US Immigration Forum | United Kingdom Immigration Forum

Main Forum RSS : RSS

Powered by: YAF.NET
Copyright © AI Logica All rights reserved.
This page was generated in 0.252 seconds.