473,670 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Registration that sends details to two e-mails

9 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['email'])) {
  3.  
  4.     require_once 'functions.php';
  5.     // EDIT THE 2 LINES BELOW AS REQUIRED
  6.     $email_to = "bolarinwaab@gmail.com";
  7.     $email_subject = "Registration Information";
  8.  
  9.  
  10.     function died($error) {
  11.         // your error code can go here
  12.         echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  13.         echo "These errors appear below.<br /><br />";
  14.         echo $error."<br /><br />";
  15.         echo "Please go back and fix these errors.<br /><br />";
  16.         die();
  17.     }
  18.  
  19.     // validation expected data exists
  20.     if(
  21.     !isset($_POST['tittle']) ||
  22.     !isset($_POST['surname']) ||
  23.         !isset($_POST['firstname']) ||
  24.         !isset($_POST['noofchildren']) ||
  25.         !isset($_POST['email']) ||
  26.         !isset($_POST['phoneno']) || 
  27.         !isset($_POST['residentialaddress']) ||
  28.         !isset($_POST['state']) ||
  29.         !isset($_POST['country']) ||
  30.         !isset($_POST['yearofgrad']) ||
  31.         !isset($_POST['department']) ||
  32.         !isset($_POST['company']) ||
  33.         !isset($_POST['attendance'])) {
  34.         died('We are sorry, but there appears to be a problem with the form you submitted.');       
  35.     }
  36.     $tittle=$_POST['tittle'];
  37.     $firstname = $_POST['surname']; // required
  38.     $lastname = $_POST['firstname']; // required
  39.     $midname=$_post['middlename'];
  40.     //$status=$_post['maritalstatus'];
  41.     $children=$_post['noofchildren'];
  42.     $email= $_POST['email']; // required
  43.     $phoneno = $_POST['phone']; // not required
  44.     $address = $_POST['residentialaddress']; // not required
  45.     $state = $_POST['state']; // not required
  46.     $country = $_POST['country']; // not required
  47.     $yearofgrad = $_POST['yearofgrad']; //required
  48.     $department = $_POST['department']; // not required
  49.     $company = $_POST['company']; // not required
  50.     $attendace = $_POST['attendance']; // not required
  51.  
  52.  
  53.     $error_message = "";
  54.     $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  55.   if(!preg_match($email_exp,$email)) {
  56.     $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  57.   }
  58.     $string_exp = "/^[A-Za-z .'-]+$/";
  59.   if(!preg_match($string_exp,$firstname)) {
  60.     $error_message .= 'The Surname you entered does not appear to be valid.<br />';
  61.   }
  62.   if(!preg_match($string_exp,$lastname)) {
  63.     $error_message .= 'The Firstname you entered does not appear to be valid.<br />';
  64.   }
  65.    /*if(!preg_match($string_exp,$midname)) {
  66.     $error_message .= 'The Middlename you entered does not appear to be valid.<br />';
  67.   }*/
  68.    /*if(!preg_match($string_exp,$status)) {
  69.     $error_message .= 'The Marital Status you entered does not appear to be valid.<br />';
  70.   }*/
  71.  
  72.    if(!preg_match($string_exp,$address)) {
  73.     $error_message .= 'The Residential Address you entered does not appear to be valid.<br />';
  74.   }
  75.  
  76.    if(!preg_match($string_exp,$department)) {
  77.     $error_message .= 'The Department name you entered does not appear to be valid.<br />';
  78.   }
  79.   if(strlen($company) < 2) {
  80.     $error_message .= 'The Company Name you entered do not appear to be valid.<br />';
  81.   }
  82.   if(strlen($error_message) > 0) {
  83.     died($error_message);
  84.   }
  85.     $email_message = "Form details below.\n\n";
  86.  
  87.     function clean_string($string) {
  88.       $bad = array("content-type","bcc:","to:","cc:","href");
  89.       return str_replace($bad,"",$string);
  90.     }
  91.       $email_message .= "Tittle: ".clean_string($tittle)."\n";
  92.       $email_message .= "Surname: ".clean_string($surname)."\n";
  93.       $email_message .= "Firstname: ".clean_string($firstname)."\n";
  94.       $email_message .= "Middlename: ".clean_string($middlename)."\n";
  95.       //$email_message .= "Marital Status: ".clean_string($maritalstatus)."\n";
  96.       $email_message .= "No of Children: ".clean_string($noofchildren)."\n";
  97.       $email_message .= "Email: ".clean_string($email_from)."\n";
  98.       $email_message .= "Telephone: ".clean_string($phoneno)."\n";
  99.       $email_message .= "Residential Address: ".clean_string($residentialaddress)."\n";
  100.       $email_message .= "State: ".clean_string($state)."\n";
  101.       $email_message .= "Country: ".clean_string($country)."\n";
  102.       $email_message .= "Year Of Graduation: ".clean_string($yearofgrad)."\n";
  103.       $email_message .= "Department: ".clean_string($department)."\n";
  104.       $email_message .= "Company: ".clean_string($company)."\n";
  105.       $email_message .= "Attendace: ".clean_string($attendace)."\n";
  106.  
  107.      //Call the email function to perform the mail sending
  108.      sendGMail($email_message, $email_subject, $email_to);
  109.  
  110. // create email headers
  111. /*$headers = 'From: '.$email_from."\r\n".
  112. 'Reply-To: '.$email_from."\r\n" .
  113. 'X-Mailer: PHP/' . phpversion();
  114. @mail($email_to, $email_subject, $email_message, $headers);  */
  115.  
  116. ?>
  117.  
  118. <!-- include your own success html here -->
  119.  
  120. Thank you for contacting us. We will be in touch with you very soon.
  121.  
  122. <?php
  123. }
  124. ?>
I have tried using this code but it seems not to be sending the mail @ all... I need your help guys thanks.
May 31 '13 #1
3 1486
Luuk
1,047 Recognized Expert Top Contributor
There is a 'CODE'-tag, please us it..... ;)

At line #3: you write: "require_on ce 'functions.php' ;"
The contents of 'functions.php' are needed to know what this line does: line #??: "sendGMail($ema il_message, $email_subject, $email_to);"

You probably just need to enable error notifications, see here to know why this fails....
May 31 '13 #2
abramfas
9 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     //Function to send email via smtp
  3.     function sendMail($message, $subject, $recipient)
  4.     {
  5.         require_once('class.phpmailer.php');
  6.         //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  7.  
  8.         $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
  9.  
  10.         $mail->IsSMTP(); // telling the class to use SMTP
  11.  
  12.         try {
  13.             $mail->Host       = "mail.yourdomain.com"; // SMTP server
  14.             $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  15.             $mail->SMTPAuth   = true;                  // enable SMTP authentication
  16.             $mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
  17.             $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
  18.             $mail->Username   = "yourname@yourdomain"; // SMTP account username
  19.             $mail->Password   = "yourpassword";        // SMTP account password
  20.             $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  21.             $mail->SetFrom('name@yourdomain.com', 'First Last');
  22.             $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  23.             $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  24.             $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  25.             $mail->MsgHTML($message);
  26.             $mail->Send();
  27.             echo "Message Sent OK</p>\n";
  28.         } catch (phpmailerException $e) {
  29.               echo $e->errorMessage(); //Pretty error messages from PHPMailer
  30.         } catch (Exception $e) {
  31.               echo $e->getMessage(); //Boring error messages from anything else!
  32.         }
  33.     }
  34.     //Function to send email via gmail account
  35.     function sendGMail($message, $subject, $recipient)
  36.     {
  37.         require_once('lib/phpmailer/class.phpmailer.php');        
  38.         $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch        
  39.         $mail->IsSMTP(); // telling the class to use SMTP        
  40.         try {
  41.          // $mail->Host       = "mail.yourdomain.com"; // SMTP server
  42.               $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  43.               $mail->SMTPAuth   = true;                  // enable SMTP authentication
  44.               $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  45.               $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  46.               $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
  47.               $mail->Username   = "bolarinwaab@gmail.com";  // GMAIL username
  48.               $mail->Password   = "password";            // GMAIL password
  49.               $mail->AddAddress($recipient, '');
  50.               $mail->SetFrom('accoutid@gmail.com', 'name of account');
  51.               //$mail->AddReplyTo('accountid@gmail.com', 'name of account');
  52.               $mail->Subject = $subject;
  53.               $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
  54.               $mail->MsgHTML($message);
  55.               $mail->Send();
  56.         } catch (phpmailerException $e) {
  57.               echo $e->errorMessage(); //Pretty error messages from PHPMailer
  58.         } catch (Exception $e) {
  59.               echo $e->getMessage(); //Boring error messages from anything else!
  60.         }
  61.     }
  62. ?>

Hi luuk this is the fuction.php file
Jun 1 '13 #3
Oralloy
988 Recognized Expert Contributor
abramfas,

Will you please use [code] tags, so that we can read your code as you wrote it, rather than with spaces compressed?

This is a BB Code list, so you can see all of the tags and how to use them.

Thanks,
Oralloy
Jun 1 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
1897
by: Bob Alston | last post by:
I am using the Outlook library to send emails from Access. I have Outlook open and run a program to respond yes to the security question (Express click Yes). It seems to take about 5 seconds for each email to get sent. Does this seem like the normal amount of time for others who do this? Any tricks to speed it up?
1
2830
by: shubhrarustagi | last post by:
hi, I'm a beginner developer and one of my first tasks is to develop automatic emails application in .net. We need to send automatic emails to users whose credit cards are expiring, create email templates... I've no idea how it is done in .Net. Any suggestions would be great!! Thanks,
0
1069
by: =?Utf-8?B?am9lbA==?= | last post by:
When I posted a comment, I received a message that you had tried 3 times to send me emails but had been unable to do so. You asked me to solve this problem. How do I solve this problem? -- joel
1
1259
by: prasath1984 | last post by:
hi, This is prasath i want the code to send bulk emails
2
2702
by: techsri | last post by:
Hi, We are going to launch a website which offers free e-learning courses to the users. we are facing some problems to build my site. The problem is about, We want add push email feature to our site. Using that feature we want to send automated emails to the users after successful registration, upon course completion etc. Please suggest us the better to complete this site. Thank you.
2
2429
by: palanisiva | last post by:
Hi, I am using PHP mailer to send out 2 different emails. The problem I am having is only the first email is ever sent out. Below is my code. The first email $to but i add two mail id mail not sending. Please help....this is urgent! $mail = new PHPMailer(); $mail->From = "palani@xxxx.com"; $mail->FromName = " manager";
3
100032
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg You can make your emails fancy in Mail.app by using Rich Text formatting or even included Stationery. But, a simple way to send your own HTML creation (or any web page for that matter) is to use Safari. Follow these four easy steps. 1. Create the HTML Layout your HTML code including any images or graphics you'd like to include. In this example, we will make a simple birthday email to add...
0
1564
by: rserrador | last post by:
Hello. I'm creating a db in access 2007 and i want to have a buton on a report where i can send bcc multiple emails from a query. Can someone help me with the VBA code please.
11
17723
by: londres9b | last post by:
I want to send multiple emails from php with one unique script. The emails are from a mysql database table. How can I achieve this?
1
2092
by: sasasasa | last post by:
How can I send emails from my Microsoft Outlook through my code. Dim OlApp As Outlook.Application doesn't even work for me. Any help will be appreciated.
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8592
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,...
0
8661
tracyyun
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...
0
7421
agi2029
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...
1
6216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.