Jump to content

Emailing Script


timothyarden

Recommended Posts

Hi Everyone,

I am currently working on a php mailing script but it is not working. I have a form which posts to a php script which is supposed to mail to the specified email address a message:

 

Here is the form

<body bgcolor="white" style="float:center;">
	<h2 style="color:black">Store Inquiries</h2><hr /><br />
	<form name="contactus" action="contactus.php" method="post">
		<table>
			<tr>
				<td style="width:280px">
					<label for="senderaddress"><b style="color:blue">Email Address</b></label><br />
				</td>
				<td>
					<input type="text" name="senderaddress" size="50"><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="recipientaddress"><b style="color:blue">Recipient Email Address</b></label><br />
				</td>
				<td>
					<input type="text" name="recipientaddress" size="50"><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="headers"><b style="color:blue">Headers</b></label><br />
				</td>
				<td>
					<input type="text" name="headers" size="50"/><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="fname"><b style="color:blue">First Name</b></label><br />
				</td>
				<td>
					<input type="text" name="fname" size="50"/><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="lname"><b style="color:blue">Last Name</b></label><br />
				</td>
				<td>
					<input type="text" name="lname" size="50"/><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="subject"><b style="color:blue">Subject</b></label><br />
				</td>
				<td>
					<br /><input type="text" name="subject" size="50"/><br /><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="message"><b style="color:blue">Message</b></label><br />
				</td>
				<td>
					<textarea type="text" name="message" rows="5" cols="37"></textarea><br /><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="contactusfileupload"><b style="color:blue">Images or other Relevant Files</b></label><br />
				</td>
				<td>						
					<br /><input type="file" name="contactusfileupload"/><br /><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="submit"></label><br />
				</td>
				<td>						
					<input type="submit" name="submit" value="Contact Us"/><br />
				</td>
			</tr>
		</table>
	</form>

 

And here is the php script

<?php	
$recipientaddress = $_POST['recipientaddress']; //contactus@websports.abodegaminggeneration.com 
$senderaddress = $_POST['senderaddress'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = $_POST['headers'];

mail($recipientaddress,$subject,$message,$headers,$senderaddress);

echo "Your email has been sent to ". $_POST['recipientaddress'].".";
?>

 

Thanks for reading and any help would greatly appreciated. Thanks guys.

Timothy

 

(If you need me to explain anything further for you to help just ask :) )

Link to comment
Share on other sites

Thank you for the response and advice. So as for not working it is not sending, if you are willing to give me your email please send it to tim.arden.rip@gmail.com and I will give you the link to my site. (I do not want to share it on a forum as it is not yet secure.)

 

HTML Form

<body bgcolor="white" style="float:center;">
	<h2 style="color:black">Store Inquiries</h2><hr /><br />
	<form name="contactus" action="contactus.php" method="post">
		<table>
			<tr>
				<td style="width:280px">
					<label for="senderaddress"><b style="color:blue">Email Address</b></label><br />
				</td>
				<td>
					<input type="text" name="senderaddress" size="50"><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="recipientaddress"><b style="color:blue">Recipient Email Address</b></label><br />
				</td>
				<td>
					<input type="text" name="recipientaddress" size="50"><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="headers"><b style="color:blue">Headers</b></label><br />
				</td>
				<td>
					<input type="text" name="headers" size="50"/><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="fname"><b style="color:blue">First Name</b></label><br />
				</td>
				<td>
					<input type="text" name="fname" size="50"/><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="lname"><b style="color:blue">Last Name</b></label><br />
				</td>
				<td>
					<input type="text" name="lname" size="50"/><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="subject"><b style="color:blue">Subject</b></label><br />
				</td>
				<td>
					<br /><input type="text" name="subject" size="50"/><br /><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="message"><b style="color:blue">Message</b></label><br />
				</td>
				<td>
					<textarea type="text" name="message" rows="5" cols="37"></textarea><br /><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="contactusfileupload"><b style="color:blue">Images or other Relevant Files</b></label><br />
				</td>
				<td>						
					<br /><input type="file" name="contactusfileupload"/><br /><br />
				</td>
			</tr>
			<tr>
				<td>
					<label for="submit"></label><br />
				</td>
				<td>						
					<input type="submit" name="submit" value="Contact Us"/><br />
				</td>
			</tr>
		</table>
	</form>

 

And here is the PHP Script

 

<?php	
$recipientaddress = $_POST['recipientaddress']; //contactus@websports.abodegaminggeneration.com 
$senderaddress = $_POST['senderaddress'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = $_POST['headers'];

mail($recipientaddress,$subject,$message,$headers,$senderaddress);

echo "Your email has been sent to ". $_POST['recipientaddress'].".";
?>

 

To anyone who is willing to help it would be greatly appreciated and thanks for your help gizmola.

Timothy Arden

Link to comment
Share on other sites

Do you have error reporting on? Are you getting any errors? I don't know what $senderaddress is supposed to be doing in the mail() function, but it isn't right. There should also be no reason to allow email headers to be defined in a web form. That's a spammer's wet dream.

Link to comment
Share on other sites

Thanks to every one for your help.

In answer to your question Pikachu2000:

 

I am not getting any errors on the page and I have just checked my logs and here is what it says :

 

[25-May-2012 01:20:36] PHP Warning:  mail() [<a href='function.mail'>function.mail</a>]: SAFE MODE Restriction in effect.  The fifth parameter is disabled in SAFE MODE in /homedirectory/userdirectory/public_html/subdomain/contactus.php on line 8

 

How would I dis-enable safe mode?

 

At the moment I am just trying to get this to work. I don't intend to allow others to use it which will avoid the create your own headers spammer problem.

 

When I was sending a simpler version of a mail script through

<form action="contactus.php" id="contactusform" method="post"><hr /><br />
<h1>Contact Us</h1><br />
<label for="recieveraddress">Email Address: </label><input type="text" id="recieveraddress"/><br />
<label for="subject">Subject: </label><input type="text" id="subject"/><br />
<label for="message">Message: </label><input type="text" id="message" height="100px" width="200px"/><br /><br />
<input type="submit" value="Submit"/><br /><hr />
</form>	

<?php
$to = "email@emailing.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$sender = $_POST['senderaddress'];
$headers = "None"
mail($to,$subject,$message,$headers);
echo "Mail Sent."; 
?> 

 

It would go through and send to the email address but it would be myusername@theserverIamhostedon. This is why I would like the sender address - I would like to change that default sending address (above) to myusername@mydomainname. (I am not sure how to do this)

 

I tried what you guys suggested - taking out $senderaddress from the mail() function and it worked (Thanks heaps :)). However as I said above I want to change the senders address to myusername@mydomainname. Any ideas? Also I want to be able to mail from this script as if I was mailing from any of my 3 email accounts so I want to be able to make a variable that will display itself instead of myusername@theserverIamhosted on.

 

Thanks for all the help guys, it is much appreciated.

Timothy Arden

 

Link to comment
Share on other sites

You were misunderstanding the way the mail function works.  The 5th parameter is for switches that are passed through to the MTA which actually delivers the mail.  You don't need it, and as you've seen it's disabled on your system.  You set your from address in the $headers parameter:

 

$headers = 'From: you@yourhost.com';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.