PHP Confirmation Email after filling out Contact Form - php

I've created a contact page for a project im working on and im having trouble getting it to send a confirmation email to the user. I have the function defined on my emailer page along with the code that sends the contact form to me
public function sendEmail(){ //this will format and send an email to the smtp server
$to = $this->getSenderEmail();
$subject = $this->getSubject();
$message = $this->getMessage();
$headers = "From: <contact#tristonnearmyer.com >";
$from = $this->getCustomerInfo();
//it will use the php mail()
return mail($to,$subject,$message,$from);
}
public function sendConfEmail(){
$userEmail = $this->getRecipientEmail();
$confSubject = "confirmation";
$confMessage = "thank you";
return mail($userEmail, $confSubject, $confMessage);
}
then the functions are used on the contact page
echo $emailTest->sendEmail(); //send email to SMTP server
echo $emailTest->sendConfEmail(); //send confirmation email
I can't seem to figure out why one is working while the other isn't

Please try this code, you need to call the function sendConfEmail after sendEmail success. Also from here you need to modify the header. But base on user3783243 commend better change to PHPMailer or use swift
public function sendEmail(){ //this will format and send an email to the smtp server
$to = $this->getSenderEmail();
$subject = $this->getSubject();
$message = $this->getMessage();
$from = $this->getCustomerInfo();
$headers = 'From: '. $from . "\r\n" .
'Reply-To: youremailhere#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$sendMail = mail($to,$subject,$message,$headers);
if($sendMail){
// Call the function send confirmation
$this->sendConfEmail();
}else{
echo 'failed sent the email';
}
}
public function sendConfEmail(){
$userEmail = $this->getRecipientEmail();
$confSubject = "confirmation";
$confMessage = "thank you";
$from = $this->getCustomerInfo();
$headers = 'From: '. $from . "\r\n" .
'Reply-To: youremailhere#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
return mail($userEmail, $confSubject, $confMessage,$headers);
}

Related

emailing confirmation to user when they submit an html registration form

I am trying to email the data in an html when you click on the submit button, the html form uses the POST action. My php code is:
<?php
$email = $_POST['email'];
$to = '$email'; //email submitted in html form
$subject = 'Welcome ';
$message = 'hello';
$headers = 'From: myaddress#email.com' . "\r\n".
'Reply-To: From: myaddress#email.com' . "\r\n".
'X-Mailer: PHP/' . phpversion();
$result = mail($to, $subject, $message, $headers);
if(!$result) {
echo "Error";
} else {
echo "Success";
}
?>
I get a success message but no email comes through, any ideas would be highly appreciated. many thanks

Send email php script

<?php
$path = 'data.txt';
if (isset($_POST['email']) ) {
$fh = fopen($path,"a+");
$string = $_POST['email'].' - '.$_POST['field2'];
fwrite($fh,$string); // Write information to the file
fclose($fh); // Close the file
}
$to = $_POST['email'];
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Can someone tell me what is wrong with this code?
I want that the script to send email to $_POST['email'] that came from a previous html file.
So first,store that email,and after that sent an email to it.
Thank you
Edit: The script store the email with success but the email is not sent.
Thanks again

What is wrong with my PHP Send Mail Function below?

What is wrong with my PHP Send Mail function? I am hosting this script on a live server.
$to = 'myemail#gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: exampleemail#gmail.com' . "\r\n" .
'Reply-To: exampleemail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)){}
else{
echo "Email sending failed";
}
I keep receiving the "Email sending Failed" message.

Unable to sent an email using codeigniter

I have a codeigniter with tank auth configured.I was doing all the test and everything was running properly on my development server.I shiftwd all my codes to the productiom server and no activation email of tank auth is being sent.I used gmail cobfiguration in the email vodeingiter config and email was sent but to some emails its not being sent.Why im i unable to sent email using the default codeigniter settinga in the production server.please help
In the function where you sending you data afte completion of task
$email = 'email on which you want to send mail';
$Subject = "Your subject message";
$smsg = null;
$smsg = 'yor message';
$email_from = 'manishatutorsbureau#gmail.com';
$header = 'From: ' . $email_from . "\r\n" .
'Reply-To: ' . $email_from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// Start code for sending mail
mail($email, $Subject, $smsg, $header);

Mail is not sent from website's PHP Contact form

i m using a php form for sending the contact email from my website. the code is ok and working fine on one website but not working in second website. both website having difference server space and hosting. Not showing any error on page
code is below :
<?php
$name = $_REQUEST['rohini_name'] ;
$contact = $_REQUEST['rohini_contact'] ;
$email = $_REQUEST['rohini_email'] ;
$remark = $_REQUEST['rohini_message'] ;
$MailTxt = "Following are Details" . "\r\n" .
"============================" . "\r\n" .
"Name : " . $name . "\r\n" .
"Mobile : " . $contact . "\r\n" .
"Email : " . $email . "\r\n" .
"Remark : " . $remark . "\r\n";
$to = "ballu9868#gmail.com";
$subject = "Enquiry from rohiniseeds.com";
$headers = "From: www.rohiniseeds.com";
mail($to,$subject,$MailTxt,$headers);
?>
Please ask your hosting to make sure that mail funstion is supported.
Try adding an IF statement around the mail($to,$subject,$MailTxt,$headers) function as follows:
if(mail($to,$subject,$MailTxt,$headers)){
echo 'Success!';
} else {
echo 'Error!';
}
If it says Success then you know that it's being sent by the server, and the problem is when it's trying to hit the inbox. If it says error, then the problem related to the server.
Also, please use email#rohiniseeds.com in the from header, which is a valid email address, instead of the URL of the website.
Please try this
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

Categories