Solved

PHP mailing list functionality

Posted on 2007-03-25
6
164 Views
Last Modified: 2008-03-06
I am new to PHP and I am searching for code to embed into my webpage that will do several things:

1. Create a form that gets a visitor's name and email address (has a 'Submit' button).
2. Adds the name and email to a list (maybe just a txt document or a database). --> Note: I don't have a database set up, and I do not know how to code one (so I would need a lot of code for this option).
3. When the submit button is clicked, an email is sent to me (xxxxxx@yahoo.com) with the updated list of emails as the body of the email. The subject is : "New member has joined"

Can you please provide code. It will really help me. Thank you so much.
0
Comment
Question by:jrwalker2
  • 2
  • 2
  • 2
6 Comments
 
LVL 2

Expert Comment

by:bandolex2
ID: 18791151
Ask in PHP forum, this is ASP.
0
 
LVL 1

Author Comment

by:jrwalker2
ID: 18791217
I have asked in a PHP forum also. If you can answer my question with ASP, I welcome the solution. I am simply searching for people who are willing to help me with my problem. Thank you
0
 
LVL 2

Expert Comment

by:bandolex2
ID: 18791239
Is not really that simple, code in asp is totally different to php and what you need to do involves a lot of stuff ... if youre using a linux hosting you should stick to php forum, there's plenty of people that will gladly help you there.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 14

Accepted Solution

by:
raja_ind82 earned 500 total points
ID: 18791613
<?php
if(isset($_POST['btnsubmit']))
{
      $fromAddress= "admin@yoursite.com";
      $toAddress= "youmail@yoursite.com";
                     $subject= "New member has joined";
      $firstName= $_POST['txtfirstname'];
      $lastName= $_POST['txtlastname'];
      $emailAddress= $_POST['txtemail'];
 
$content = <<<EOD
$content
<html>
<head>
      <title>New User register!!!</title>
</head>
<table>
      <tr>
            <td>FirstName:</td>
            <td><b>%FNAME%<b></td>
      </tr>
      <tr>
            <td>LastName:</td>
            <td><b>%LNAME%<b></td>
      </tr>
      <tr>
            <td>EMail:</td>
            <td><b>%MAILADDRESS%<b></td>
      </tr>
      <tr>
            <td colspan='2'>Regards,<br>Support Team</td>
      </tr>
</table>
</html>
EOD;

$bodytag = str_replace("%FNAME%",$firstName,$content);
$bodytag = str_replace("%LNAME%",$lastName,$bodytag);
$bodytag = str_replace("%MAILADDRESS%",$emailAddress,$bodytag);
 
send_mail($fromaddress,$toaddress,$subject,$bodytag);
}

/*****FUNCTION TO SEND EMAIL STARTS*****/
function send_mail($fromaddress,$toaddress,$subject,$bodymessage)
{
      $headers  = "MIME-Version: 1.0\r\n";
      $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
      $headers .= "Content-type: text/html;\r\n";
      $headers .= "From: ".$fromaddress."\r\n";
      @mail($toaddress,$subject,$bodymessage,$headers);
      return true;
}
/*****FUNCTION TO SEND EMAIL ENDS*****/
?>

<HTML>
<HEAD>
<TITLE>Raja's Example</TITLE>
</HEAD>
<BODY>
<form name="frmname" action="send_mail2.php" method="POST">
<TABLE>
<TR>
      <TD>First Name:</TD>
      <TD><input type="text" name="txtfirstname"></TD>
</TR>
<TR>
      <TD>Last Name:</TD>
      <TD><input type="text" name="txtlastname"></TD>
</TR>
<TR>
      <TD>Email Address:</TD>
      <TD><input type="text" name="txtemail"></TD>
</TR>

<TR>
      <TD><input type="submit" name="btnsubmit" value="submit"></TD>
      <TD></TD>
</TR>
</TABLE>
</form>
</BODY>
</HTML>

Regards,
M.Raja
0
 
LVL 1

Author Comment

by:jrwalker2
ID: 18793586
Thank you so much raja_ind82! I have a followup question...I have an exisiting page (page.html). Do I rename it to page.php? Is there something special that I need to do to get this working (I have tried both .php and .htm and neither work)? Also, if I want it sent straight to my gmail account, can the set the variables like this?:

 $fromAddress= "admin@gmail.com";
 $toAddress= "xxxxxxxx@gmail.com";

where xxxxxxxx is my user name.
0
 
LVL 14

Expert Comment

by:raja_ind82
ID: 18801696
if you want to any php scripting in that, then rename it to "page.php".
you can set any type value in the to address. do you want to change this in dynamically.
if you want get form the database, using any id and can get the details from the database. if you have any specific question feel free to ask me....

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question