[PHP] Newsletter Subscription Form -MailHandler Script

Status
Not open for further replies.

St0neF!sh

Active Member
128
2012
52
0
Hello Coders,
I have coded a website(html with js), where I want to place a Newsletter/updates subscription box.
I have coded the design and html for the same, but unable to code the PHP mail-handler.
I have searched through Google and now, I have something in my mind....

1. Is it possible to create a DB for all registered emails, and can access get a complete full/incremental updates in email list through some logins?

2. Is it only a mail notification for me that some one registered himself for newletter and I have to add his mail id in my list manually?

3. Is there any auto grouping concept like, I have to send mail to only one ID and it will automatically sent to all registered mail ids which can be fetched from DB?

Please suggest me an appropriate and best solution.

BTW, my HTML form code is as below:

Code:
<!--subscribe form here-->
<form id="subform" method="post" action="subscribe/subscribe.php">
<fieldset>
<p><input name="email" id="email" onfocus="if (this.value == 'Email') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Email';}" value="Email" class="required email" /></p>
<div class="button button-orange"> <span class="form_button clearfix"><input class="sub_submit" name="submit" value="subscribe" type="submit" /></span> </div>
<div id="result_sub"></div></fieldset></form><!--subscribe form ends-->
<div class="clear"></div></div></div><!--box ends-->
<div class="clear"></div></div></div></div><!--section for subscribe ends-->


Thanks for your support and co-operation.
Regards,
sf
 
12 comments
you're solution is

Add the following code to your HTML page:


Code:
<form method="POST" action="enter the URL to your PHP page here">
<p>Name: <input type="text" name="Name" size="20"></p>
<p>Email: <input type="text" name="Email" size="20"></p>
<p><input type="submit" value="Submit" name="Submit"></p>
</form>

Create a new PHP file (e.g. subscribe.php) and place it on your webserver.

Please update the URL in the HTML form.

Code:
<?php

## CONFIG ##

# LIST EMAIL ADDRESS
$recipient = "enter the lists email address here";

# SUBJECT (Subscribe/Remove)
$subject = "Subscribe";

# RESULT PAGE
$location = "enter the URL of the result page here";

## FORM VALUES ##

# SENDER
$email = $_REQUEST['Email'] ;

# MAIL BODY
$body .= "Name: ".$_REQUEST['Name']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
# add more fields here if required

## SEND MESSGAE ##

mail( $recipient, $subject, $body, "From: $email" ) or die ("Mail could not be sent.");

## SHOW RESULT PAGE ##

header( "Location: $location" );
?>

Now save both files to your webserver and click on "Submit".
The php script will not work on your local computer - please upload it first.
 
you're solution is

Add the following code to your HTML page:
........
.........
..........

Now save both files to your webserver and click on "Submit".
The php script will not work on your local computer - please upload it first.


If I am not wrong, you forgot to mention the bottom tag: :facepalm:

I have already told before that I have Google'd it, and finding the exact solution probably from a coder.... ;)
 
There are loads of mailing lists scripts, just install one and add the form data to your site, pommo is one but there will be far better updated ones.
 
There are loads of mailing lists scripts, just install one and add the form data to your site, pommo is one but there will be far better updated ones.

I know that there are lots of scripts available and thats why I have raised some questions... And also want to get suggestions and personal experiences from other members as well as want to know that which one is better and can be implemented easily with max possibilities....

Rgds,
sf
 
To setup what you had mentioned, you will likely need to learn a little bit.
You can create a secure admin panel, or otherwise upload/remove the .php script which will use a 'while' function to mass send your mail to the mailing list.

You will however have to collect those mails into a database first..
Including something like the following into the mentioned contact form after setting up a database will let you acquire those.

<?php
include("config.php");

if(isset($_POST['subscribe'])) {
$submail = $_POST['email'];

$result = mysql_query("SELECT email FROM subscribers WHERE email='$submail'") or die(mysql_error());
if (mysql_num_rows($result)==1) echo " ";
else {
$sql = "INSERT INTO subscribers (email) VALUES ('$submail')";
$query = mysql_query($sql);}
}

?>
 
I cant get you...
Just let me know what will be the simple procedure for getting someones mail ID(who have entered their ID to receive the newsletter) into my mail ID...
Please come with complete code, I am quite noob in PHP...
 
If you are only looking to receive a simple email containing the subscriber's email, the script mentioned previously before my post will work fine.

You will then need to collect the emails and put them into a text file or list for later mailing - which too will have to be done manually..
This gets tedious fast, especially if you are getting plenty of subscribers.
 
I have tried that before, but something slipped, I don't know what, but didn't worked...
Tell me one thing bro, my domain is not yet propagated... is there any issue occurred due to that reason?

My site is still in development phase, and can be browsed through temp url only...
 
You will need to have the script online/hosted to run properly, because it is a PHP file. Try it on a sub domain, or when it is setup.
Using an html to call a php file on localhost will not work as you want.

Here is the form (contact.php) I use personally, very simplistic and versatile (commented out the extras)

<?php
if(isset($_POST['contact'])) {



$sendmail = 'receivinginbox@mail.com';
$clientmail = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];



// if ($clientmail == '') {
// header('Location: contact.php?error=incomplete');
// exit();
// }

// if ($message == '') {
// header('Location: contact.php?error=incomplete');
// exit();
// }

// if ($name == '') {
// header('Location: contact.php?error=incomplete');
// exit();
// }


//Send Mail

$subject = "New message From ".$name;

$sendmessage = "You have received a message from ".$name." at the contact address ".$clientmail."

They said:

------------------------------------

".$message."

------------------------------------

This message was sent from MyWebsite.com
";

mail($sendmail, $subject, $sendmessage);

header('Location: contact.php?mail=sent');
exit();

}

?>

<?php
//if($_GET["mail"] == "sent")
// echo '<p style=" padding-left: 15px; color: #666666;"><b>Thanks for your message - We strive to answer all responses in 24 hours</b></p>';
//if($_GET["error"] == "incomplete")
// echo '<p style=" padding-left: 15px; color: red;"><b>Error - Please fill in the form completely!</b></p>';
?>
<form action="" method="post" id="contact" name="contact" class="submitform" />
<div><label>Name*</label><input type="text" name="name" /></div>
<div><label>Email*</label><input type="text" name="email" /></div>
<div><label>Message*</label><textarea name="message"></textarea></div>
<div class="send-wrap">
<div class="alignleft">
<input class="send" type="submit" name="contact" id="contact" value="Send">
</div>
<span class="alignright">* required</span>
</div>
</form>
 
<?php
if(isset($_POST['contact'])) {



$sendmail = 'receivinginbox@mail.com'; //should be my mail id...right?
$clientmail = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];



// if ($clientmail == '') {
// header('Location: contact.php?error=incomplete');
// exit();
// }

// if ($message == '') {
// header('Location: contact.php?error=incomplete');
// exit();
// }

// if ($name == '') {
// header('Location: contact.php?error=incomplete');
// exit();
// }


//Send Mail

$subject = "New message From ".$name;

$sendmessage = "You have received a message from ".$name." at the contact address ".$clientmail."

They said: //whats that?

------------------------------------

".$message."

------------------------------------

This message was sent from MyWebsite.com
";

mail($sendmail, $subject, $sendmessage);

header('Location: contact.php?mail=sent');
exit();

}

?>

Please see bold strings...
 
Yes, the first part is the inbox which will receive all of the mails.
It is not uncommon to have problems sending from one server to another servers mailbox - so expect that eventually too.

The second bold "They Said" is contained within a variable that will be displayed in the message you receive.
This contact form will send you a message like this:


You have received a message from (name input) regarding (subject input)

They said:

------------------------------------

(message input)

------------------------------------

This message was delivered from MyWebsite.com
 
Status
Not open for further replies.
Back
Top