properly setting email subject line delivered from email form - forms

I have a email form for my website but here is the issue: when i receive an email, the subject line in my inbox shows whatever the user inputted as subject in the form. id like to override that so that whenever an email comes in. the subject in the email header is always "an inquiry from your website". In the message body, sure i don't mind their specific subject they entered but when I receive an email, id like consistency in my inbox.
this is the current code:
<?php session_start();
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'xxxxxxxxx';
$fromsubject = 'An inquiry from your website';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $nome <$mail>\r\n";
$to = $youremail;
$mailsubject = 'Message received from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$fname.' '.$lname.'
Address: '.$address.'
'.$city.', '.$zip.', '.$country.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Subject: '.$subject.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you for inquiring. We will contact you shortly.<br/>You may return to our <a href='/index.html'>Home Page</a>";
mail($to, $subject, $body, $headers);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, you have provided an invalid security code';
}
} else {
echo "You must write a message. </br> Please visit our <a href='/contact.html'>Contact Page</a> and try again.";
}
?>

It appears as though you have set a variable called $subject elsewhere.
$subject = $_POST['subject'];
and then use that same variable to send your mail.
mail($to, $subject, $body, $headers);
Try creating another variable for the second use or changing it prior to suit your needs.

Related

Error in mail configuration in php

I designed my website and hosted on my amazon ec2 instance and I bought my domain in godaddy (www.mydomain.com).Now I want a mail configuration in my contact form page in website.. Below its my code , I don't know where am I mistake the code?
<?php
if(isset($_REQUEST['submit'])) {
try {
$name = $_POST['name'];
echo "<script type='text/javascript'>alert('$name')</script>";
$email = $_POST['email'];
echo "<script type='text/javascript'>alert('$email')</script>";
$subject = $_POST['subject'];
echo "<script type='text/javascript'>alert('$subject')</script>";
$message = $_POST['message'];
echo "<script type='text/javascript'>alert('$message')</script>";
$response ="";
$body ="<div style='font-size:18px'>
<b>Name</b> : $name <br />
<b>Email address</b> : $email <br />
<b>Message</b> : $message <br />
</div>"
$to = "XXXXX#gmail.com";
require_once($_SERVER['DOCUMENT_ROOT'].'/samplemail/lib/class.phpmailer.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/samplemail/lib/class.smtp.php');
$mail = new PHPMailer(true);
//$mail->Host = "relay-hosting.secureserver.net"; // your SMTP Server
// echo $res;
$mail->IsSMTP();
$mail->Host = "email-smtp.us-east-1.amazonaws.com";
$mail->SMTPDebug = true;
$mail->SMTPAuth = true; // Auth Type
$mail->Port = 25;
$mail->IsSendmail();
//$mail->SMTPSecure = "ssl";
$mail->Username = "support#mydomain.com";
$mail->Password = "******";
$mail->Sender = "supportexample#mydomain.com";
$mail->From = "supportexample#mydomain.com";
$mail->AddReplyTo($email);
$mail->FromName = "Example";
$mail->AddAddress($to);
//$mail->AddAddress("desired recipient no.2 optional");
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->WordWrap = 50;
If($mail->Send()){
echo "<script type='text/javascript'>alert('Mail Send Successfully')</script>";
}
} catch (phpmailerException $e) {
echo "<script type='text/javascript'>alert('Failed')</script>";
echo $e->errorMessage();
}
}
?>
I got this error. How do solve this issue?
Could not execute: /var/qmail/bin/sendmail
You can't call random functions and expect it to all work magically.
You're setting up for SMTP with isSMTP(), but then ignoring all that by calling isSendmail(), when it looks like your server simply isn't set up for it. Why do that? Re-enable isSMTP and configure your script for your mail server correctly.
You're also requesting auth while disabling encryption; that's likely to fail on any modern server.
You're also using an old version of PHPMailer, and you've based your code on an obsolete example. Get the latest, and base your code on the examples provided.

contact form not sending email to my specific address

I have a php contact form on my website. It sends me email on my normal address. But when I put in the desired mail recipient address in the 'to' section. I do not get any email. What could be the issue??
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$number = $_POST['number'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = ' Contact Form';
$to = '';
$subject = 'Message from Website contact page ';
$body ="From: $name\n Number: $number\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
if (!$_POST['number']) {
$errNumber = 'Please enter your mobile number';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
// If there are no errors, send the email
if (!$errName && !$errNumber && !$errEmail && !$errMessage ) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! We will get in touch with you soon.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}
}
?>
can you check this:
$to = "desiredmailID#example.com, yourmailID#example.com";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: noreply#example.com" . "\r\n";
// Check if name has been entered
$errName = '';
if ($_POST['name'] == '') {
$errName = 'Please enter your name';
}
//Other validation messages here...
// If there are no errors, send the email
if ($errName == '' && $errNumber == '' && $errEmail == '' && $errMessage == '' ) {
if (mail ($to, $subject, $body, $headers)) {
$result='<div class="alert alert-success">Thank You! We will get in touch with you soon.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}

PHPMailer attachment is not receiving

I have written code for sending mail with pdf file as attachment , mail sending is working. I used class.phpmailer.php. Below is my code.
$mpdf=new mPDF();
$mpdf->ignore_invalid_utf8 = true;
$stylesheet = file_get_contents('appstyle_pdf.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($output);
$comname = preg_replace("/[^A-Za-z0-9]/","",$_POST['company']);
$name = $dirname.str_replace(" ","-",$comname)."_".$time_stamp.".pdf";
$mpdf->Output($name,"F");
$filename = basename($name);
$file_size = filesize($name);
$content = chunk_split(base64_encode(file_get_contents($name)));
$mail = new PHPMailer;
$msg = 'Message';
$body = '<html><body><p>' . $msg . '</p></body></html>'; //msg contents
$body = preg_replace("[\\\]", '', $body);
$mail->AddReplyTo('no-replay#enkapps.com', "ACIC");
$mail->SetFrom('orders#enkapps.com', "ACIC Order");
$address = 'narendar_medoju#tecnics.com'; //email recipient
$mail->AddAddress($address, "NAME");
$mail->Subject = 'SUBJECT of ACIC order form';
$mail->MsgHTML($body);
$mail->AddStringAttachment($content , $filename);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent Successfully please check attachement!";
}
When I use the above code attachment is coming to mail but file is corrupting. The error message is like "Adobe reader could not open abc.pdf because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."
Why are you doing this?
$content = chunk_split(base64_encode(file_get_contents($name)));
...
$mail->AddStringAttachment($content , $filename);
That's completely unnecessary. Just do this:
$mail->addAttachment($name);
Also I suspect you are using an old version of PHPMailer; get the latest from github.

how do i send an email through joomla

I have a system so folks can register for a class through my Joomla site (I believe it's 3.0). But from there, I would like to send folks an email filling variables from the registration. So something like:
Dear (name), thank you for registering for (class).
This is to remind you your class is tomorrow, (date), at (place).
I believe for the registration, the system uses authorize.net
How can I accomplish this?
Thanks for the help!!
You can use JFactory:getMailer like suggested in the following post. I'm copying here his code example (modified it a bit):
$subject = "Here is the subject of your message.";
$body = "Here is the body of your message.";
$user = JFactory::getUser();
$to = $user->email;
$from = array("me#mydomain.com", "Brian Edgerton");
# Invoke JMail Class
$mailer = JFactory::getMailer();
# Set sender array so that my name will show up neatly in your inbox
$mailer->setSender($from);
# Add a recipient -- this can be a single address (string) or an array of addresses
$mailer->addRecipient($to);
$mailer->setSubject($subject);
$mailer->setBody($body);
# If you would like to send as HTML, include this line; otherwise, leave it out
$mailer->isHTML();
# Send once you have set all of your options
$mailer->send();
That's all there is to it for sending a simple email. If you would like to add carbon copy recipients, include the following before sending the email:
# Add a blind carbon copy
$mailer->addBCC("blindcopy#yourdomain.com");
Another alternative is using JMail::sendMail: http://docs.joomla.org/API17:JMail::sendMail
Fetch the Mail Object:
`$mailer = JFactory::getMailer();`
Set a Sender
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
$mailer->setSender($sender);
Recipient
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
Create the Mail
$body = 'Body Text';
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
Sending the Mail
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ';
} else {
echo 'Mail sent';
}
https://docs.joomla.org/Sending_email_from_extensions

confirmation email

I've got this php code to send the users information from the contact form to my email address, but i don't know how to send a confirmation email back to the user when he fills out the form.
<?
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$areacode_telephone = $_REQUEST['areacode_telephone'] ;
$telephone = $_REQUEST['telephone'] ;
$email = $_REQUEST['email'] ;
$notes = $_REQUEST['notes'] ;
$body = " Name: ".$name."\n
Company: ".$company."\n
Area Code: ".$areacode_telephone."\n
Telephone: ".$telephone."\n
Email Address: ".$email."\n
Notes: ".$notes;
mail( "info#axsiom.com.au", "Axsiom: Contact Us", $body, "From: $email" );
?>
You are just reusing the same variables in a different combination using the same function just to send it back to them.
mail( $email, "Thank You", "We Have Recived Your Request blablabla", "From: info#axsiom.com.au" );
Tada.
To send the same message to both you and them use:
<?php
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$areacode_telephone = $_REQUEST['areacode_telephone'] ;
$telephone = $_REQUEST['telephone'] ;
$email = $_REQUEST['email'] ;
$notes = $_REQUEST['notes'] ;
$body = " Name: ".$name."\n
Company: ".$company."\n
Area Code: ".$areacode_telephone."\n
Telephone: ".$telephone."\n
Email Address: ".$email."\n
Notes: ".$notes;
mail( "info#axsiom.com.au, $email", "Axsiom: Contact Us", $body, "From: $email" );
?>
To send a different message to both you and them use:
<?php
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$areacode_telephone = $_REQUEST['areacode_telephone'] ;
$telephone = $_REQUEST['telephone'] ;
$email = $_REQUEST['email'] ;
$notes = $_REQUEST['notes'] ;
$body = " Name: ".$name."\n
Company: ".$company."\n
Area Code: ".$areacode_telephone."\n
Telephone: ".$telephone."\n
Email Address: ".$email."\n
Notes: ".$notes;
//to you
mail( "info#axsiom.com.au", "Axsiom: Contact Us", $body, "From: $email" );
//to them
mail( $email, "Thank You", "We Have Recived Your Request blablabla", "From: info#axsiom.com.au" );
?>
To send email:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#gmail.com'; // Your gmail username
$mail->Password = 'your_gmail_password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'from#example.com'; // from email address
$mail->FromName = 'User1'; // whatever is the name of sender
$mail->addAddress($_POST['email'], $_POST['username']); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message ;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>