This is my script..... -
<?php
-
-
$to = "example@example.co.uk";
-
$subject = "subject";
-
-
//minimum characters allowed in the message box
-
$msg_min_chars = "10";
-
-
//maximum characters allowed in the message box
-
$msg_max_chars = "250";
-
-
function validate_form_items()
-
{
-
global $msg_min_chars, $msg_max_chars;
-
$msg_chars = "{".$msg_min_chars.",".$msg_max_chars."}";
-
-
$form_items = array(
-
-
"name" => array(
-
"regex" => "/^([a-zA-Z '-]+)$/",
-
"error" => "Name appears to be in inproper format",
-
),
-
"email" => array(
-
"regex" =>
-
"/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/",
-
"error" => "Please enter a valid email address",
-
),
-
"message" => array(
-
"regex" => "/^.{$msg_chars}$/",
-
"error" => "Your message is either too short or exceeds $msg_max_chars characters",
-
),
-
);
-
-
$errors = array();
-
-
foreach($form_items as $item_name => $item_props)
-
{
-
if (!preg_match($item_props["regex"], trim($_POST[$item_name])))
-
{
-
$errors[] = $item_props["error"];
-
}
-
}
-
-
return $errors;
-
}
-
-
function email($from, $to, $subject, $message)
-
{
-
$headers = "From: ".$from."\r\n";
-
$headers .= "Reply-To: ".$from."\r\n";
-
$headers .= "Return-Path: ".$from."\r\n";
-
-
if (mail($to,$subject,$message,$headers) ) {
-
echo "Thank you for your inquiry, Your message has been received. <br>We will get back to you as soon as we can.";
-
} else {
-
echo "Your message could not be sent at this time. Please try again.";
-
}
-
}
-
-
function print_error($errors)
-
{
-
foreach($errors as $error)
-
{
-
echo $error."<br>";
-
}
-
}
-
-
function form_process()
-
{
-
global $to, $subject;
-
-
$errors = validate_form_items();
-
-
if(count($errors) == 0)
-
{
-
$errors [] = email(trim($_POST["email"]), $to, $subject, $_POST["message"]);
-
}
-
-
print_error($errors);
-
}
-
-
form_process();
-
-
?>
-
My form...... -
<form id="test" method="post" onsubmit="return false;">
-
<table border="0">
-
<tr>
-
<td colspan="2">
-
-
<div id="errors">
-
-
</div>
-
-
</td>
-
</tr>
-
-
<tr>
-
<td colspan="2">
-
-
<font size="+2"><b>Email Us</b></font>
-
-
</td>
-
</tr>
-
-
<tr>
-
<td>
-
<b>Name:</b>
-
-
<input type="text" name="name" id="name" size="25" maxlength="20" />
-
</td>
-
</tr>
-
-
<tr>
-
<td>
-
<b>Email:</b>
-
-
<input type="text" name="email" id="email" size="25" maxlength="35" />
-
</td>
-
</tr>
-
-
<tr>
-
<td>
-
<b> Message:</b>
-
</td>
-
<td>
-
<i>(max 250 characters allowed)</i>
-
</td>
-
</tr>
-
<tr>
-
<td colspan="2">
-
<textarea name="message" id="message" cols="36" rows="10"></textarea>
-
</td>
-
</tr>
-
<tr>
-
<td colspan="2" align="right">
-
<input type="submit" value="submit" name="submit" onclick="javascript: sendRequest();" />
-
</td>
-
</tr>
-
</table>
-
</form>
-
-
please help 9 2609
Many things could cause the email not to send, or appear not to send. Are you getting any errors? Does it say its send its but you don't get the email? In anything in the error logs?
A few problems I had when first using the mail() function was that php.ini needed to use the full path to sendmail, the message text needs each line to be less than 70 characters long, and of course, my spam filter kicked it every time. Giving more detail should help us figure out your problem.
I just noticed this line - <form id="test" method="post" onsubmit="return false;">
Why are you doing a "return false"? That will cause the form not to submit at all, which could be your whole problem right there.
Dear labmonkey111 ,
luke noob is using a javascript to send the form...
And php mail( ) does not require the path to send mail. i think you thought of perl mail( ).
Dear luke noob,
First of all your sendRequest( ) function is not given in the code... I'm assuming its having a basic validation and submit code (line#52 in form code)
In your mail function php code try the code below at line#53 -
$sent = @mail($to,$subject,$message,$headers);
-
-
if ($sent ) {
-
echo "Thank you for your inquiry, Your message has been received. <br>We will get back to you as soon as we can.";
-
} else {
-
echo "Your message could not be sent at this time. Please try again.";
-
}
-
coz I encounter not sending mail if my code mail() in a if condition.. dunno the reason why.
You may also check if the mail function fails for real thru -
mail($to,$subject,$message,$headers) or die("Mail function failed");
-
Try this...
Thanks for the reply, i have used a bit of ajax that is not shown here it is -
<style>
-
#errors
-
{
-
-
font-size:14px;
-
font-weight:normal;
-
margin:0px;
-
padding:0px;
-
}
-
</style>
-
-
<script type="text/javascript" src="js/prototype.js"></script>
-
<script type="text/javascript">
-
-
function sendRequest() {
-
-
new Ajax.Request("email_form_process.php", {
-
method: 'post',
-
postBody: "name="+$F("name")+"&email="+$F("email")+"&message="+$F("message"),
-
onComplete: showResponse
-
-
});
-
}
-
-
-
function showResponse(req)
-
{
-
$('errors').style.borderStyle= "solid";
-
-
var res=/message was received/;
-
-
if(req.responseText.match(res))
-
{
-
$('errors').style.borderColor= "green";
-
$('errors').style.color="green";
-
}else{
-
$('errors').style.borderColor= "red";
-
$('errors').style.color="red";
-
}
-
-
$('errors').style.borderSize= "1px";
-
$('errors').innerHTML= req.responseText;
-
}
-
-
</script>
-
i tryed again today and it works. For some reason it didnt yesterday,
i have another problem though, i have an input feild for the name to be enterd, but when i post it to my email address the name does not show there, i have tryed to edit this to work but its not working still, could you give me some advice please. my input for the name, is "name" but im not sure where to edit my script.
ooh...
check your first code php script line#49 -
$headers = "From: ".$from."\r\n";
-
to -
$headers = "From: ".$name." <".$from.">\r\n";
-
then you will get name of the sender...
Hope this will help...
Perfect thank you, I last thing...
Is it possible to sent to two different email addresses at the same time, by changing line 3, somehow -
-
$to = "example@example.co.uk";
-
itz not a serious thing but it would make life a bit easier.
I think you can have $to as an array...
Regards
Dheeraj Joshi
@dheerajjoshim
No dear... php mail function can mail to multiple recipients by giving all the addresses as a coma seperated string... thats all... -
$to = "example@example.co.uk, example@example.co.au, example@example.co.ar";
-
Thank you this helps alot.
Thanks for the info Gopan..
I did not know that..
Regards
Dheeraj Joshi
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: David Burson |
last post by:
Hi,
I have a VB.NET windows app that needs to automatically send a simple text
email when my users run a new version of the app for the first time. I
thought this would be simple, but after days of reading posts and testing, I
see it is not - unless I'm missing something? I'm not an email guru.
All of my users will be running at least Windows 2000, most on XP sp2. Some
of my users will have Outlook, many will be using Outlook...
|
by: Mike |
last post by:
Is there a way to determine what a user's default email client is? I
read a post from 3 years ago that said no. I guess I'm hoping
something has come along since then.
|
by: supz |
last post by:
Hi,
I use the standard code given below to send an email from an ASP.NET
web form. The code executes fine but no Email is sent. All emails get
queued in the Inetpub mail queue.
I'm using my local default SMTP Server and my from address is a valid
Yahoo/Hotmail address. I have configures the local SMTP Server to allow
the IP Address 127.0.0.1.
|
by: nigel.t |
last post by:
Using linux
<?php
exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$returnval);
?>
or perhaps try it on your system and tell me if it does/doesnt and what
your linux is?
I've also tried
|
by: RAB |
last post by:
I have a .aspx page with the following code:
<% @Import Namespace="System.Web.Mail" %>
<%@ page language="vb" debug="true" runat="server" %>
<script runat="server">
Sub Click(sender as Object, e as EventArgs)
'Create an instance of the MailMessage class
| |
by: Sand Yaah |
last post by:
In my Ajax Code:
function selDistServe()
{
alert("SelDistServe");
url = "http://gistest/newkerala/LinkHtml";
xmlHttp = initRequest();
xmlHttp.onreadystatechange = selDistProcess;
xmlHttp.open("GET", url, true);
|
by: glubber |
last post by:
I have a cronned perl script that runs on a different server.
when I try to restore it to the server below things dont copy across correctly.
the target server is described below.
debian 4.0 - Linux testbox.jumboentertainment.com.au 2.6.18-4-686 #1 SMP Mon Mar 26 17:17:36 UTC 2007 i686 GNU/Linux
with the latest apt-get installation of postgres
|
by: gamesforums |
last post by:
Hi!
I have some code within the Application_Start event in Global.asax
that runs a sqlscript against my sql server to check the databas
version. My problem is that sometimes the Application_Start event
doesnt fire, it skips it and goes directly to my default.aspx file.
I do the following:
1. IISReset.
|
by: Dany13 |
last post by:
hi all.
i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for showing curent data in dataset . in end i am calling update metod to insert data in sql database but this metod doesnt work correctly.
at all doesnt work. but givenot any error .
fill data from my database (work propebly)
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |