Solved

PHP mailing list functionality

Posted on 2007-03-25
6
160 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now