I was trying to put a simple contact form on my site. I used a template I made on a earlier project, but for some reason it doesn't seem to be working?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['msg'];
$name = strip_tags($name);
$email = strip_tags($email);
$msg = strip_tags($msg);
$email_to = "my.email#email.com";
$email_subject = "Uusi yhteydenotto";
$email_message = "Uusi yhteydenotto: ";
$email_message = "\nName:" .$name.;
$email_message = "\nE-mail:" .$email.;
$email_message = "\n\nMessage:" .$msg.;
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
I think this contains all the necessary things for it to work, but it doesn't seem to work?
Keeps on giving me the error 500. The server should be PHP5 -approved so that shouldn't be the problem
should use concatenation operator ., your code should now look like below
$email_message = "Uusi yhteydenotto: ";
$email_message .= "\nName:" . $name;
$email_message .= "\nE-mail:" . $email;
$email_message .= "\n\nMessage:" . $msg;
Try
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['msg'];
$name = strip_tags($name);
$email = strip_tags($email);
$msg = strip_tags($msg);
$email_to = "my.email#email.com";
$email_subject = "Uusi yhteydenotto";
$email_message = "Uusi yhteydenotto: ";
$email_message .= "\nName:" .$name; /* removed .; */
$email_message .= "\nE-mail:" .$email; /* removed .; */
$email_message .= "\n\nMessage:" .$msg; /* removed .; */
/* change `$email_from` in $headers = 'From: '.$email_from."\r\n". */
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
Related
I need to attach Outlook calendar file (.ics) to the email with mail function.
This is what I have now, but it is not working.
<?php
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$companyname = $_POST["company"];
$file = "webinar-041016.ics";
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
$EmailTo = "mail#mail.com";
$Subject = "New Webinar Registration";
// prepare email body text
$Body .= "Firstname: ";
$Body .= $firstname;
$Body .= "\n";
$Body .= "Lastname: ";
$Body .= $lastname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $companyname;
$Body .= "\n";
$headers = 'From: mail#mail.com' . "\r\n" .
'Reply-To: mail#mail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$conf_subject = "Registration Complete ...";
$conf_body = "Dear " . $firstname . ",\n\nThank you..." ;
$conf_body .= "Content-Type: text/calendar; name=\"".$file."\"\r\n" ;
$conf_body .= "Content-Transfer-Encoding: quoted-printable\r\n";
$conf_body .= "Content-Disposition: attachment; filename=\"".$file."\"\r\n\r\n";
$conf_body.= $content."\r\n\r\n";
$conf_headers = 'From: web#mail.com' . "\r\n" .
'Reply-To: web#mail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// send email
$success = mail($EmailTo, $Subject, $Body, $headers);
$conf_mail = mail($email, $conf_subject, $conf_body, $conf_headers);
// redirect to success page
if ($success){
echo "success";
}else{
echo "invalid";
}
//Attached is an Outlook calendar invite so that you can plan your day accordingly.\n\n
?>
What should I do here? Is my encoding wrong?
You might have already seen this:
PHP Sending Mail
As a suggestion you might wanna have a look into PHPMailer which narrows down the work you have to do, to a single line of code:
$mail->addAttachment('/var/tmp/file.tar.gz');
I'm trying to put together a simple feedback form which uses PHP to email the results to us. The script works once, we get the email as intended.. but every time afterwards, there's no email and no error. Anyone have any idea why?
<?php
$email_to = "admin#urbansushi.com";
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$date = $_POST['date']; // required
$email_subject = "New feedback from CUSTOMER";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Date of Visit: ".clean_string($date)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
You are concatenating to $email_message but are not declaring it initially:
$email_message .= "Name: ".clean_string($name)."\n";
Try adding this
$email_message = "";
$email_message .= "Name: ".clean_string($name)."\n";
also you have whitespace before your php declaration - try removing it so that the php declaration is at the start of the file
<?php
back again. I wanted to know if there's anyway to specify a particular file for the recipients so that it sends to the emails in the file instead of having to put a comma between all of the emails. Thanks
<?php
$name = $_POST['Chase'];
$email = $_POST['email'];
$message = 'my message';
$from = 'From: email#domain';
$to = 'Email.txt(herE)';
$subject = 'hi world';
$body = "From: $name\r\n E-Mail: $email\r\n Message:\r\n $message";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: email#domain' . "\r\n" .
'Reply-To: ' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (!mail($to, $subject, $message, $headers)) { echo "Error Sending Email!"; }
else
{ echo "Mail sent!"; }
You could use something like this :-
Note :- Make sure you From email is active when you're hosting this on a server accessible via domain.
$name = "some name";
$email = "test#gmail.com";
$message = 'my message';
$subject = 'hi world';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: youremail#yourdomain.com' . "\r\n" .
'Reply-To: ' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$handle = fopen("emails.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
if (!mail($line, $subject, $message, $headers))
{
echo "Error Sending Email!";
}
else
{
echo "Mail sent!";
}
} //while
fclose($handle);
}//if - outer
else
{
echo "can't open file";
}
emails.txt
test#gmail.com
foo#gmail.com
You can add more emails to the text file, without adding a comma.
P.s :- I'd highly recommend you to use phpmailer.
File security
Make sure that you protect the text file through .htaccess, this is very important.
Here is a Q&A on the subject on Stack:
Allow scripts to read a file but prevent users from viewing the file directly
You can further your research by using "how to protect a text file php" as keywords in your favorite search engine.
I'm using the following which sends email fine but doesn't set the reply-to address and I can't figure out why.
$name = $_POST['name'];
$email = $_POST['email_addr'];
$phone = $_POST['phone'];
$body = $_POST['body'];
$body = stripslashes($body);
$message = "Email from site.\n\n
From: $name\n
Email: $email\n
Phone: $phone\n\n
Message: $body";
$to = 'darren#mysite.com';
$subject = 'From Site';
$message = $message;
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Am I missing something obvious?
I am a beginner in php.
I am trying php to send mail.
My mail goes to mail client but it does not show the header part well as I wanted.
I am using the following codes ----
<?php
//validation expected data exists
if(!isset($_POST["name"]) ||
!isset($_POST["city"]) ||
!isset($_POST["email"]) ||
!isset($_POST["phone"]) ||
!isset($_POST["message"])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
//Subject
$name = $_POST["name"];
$subject = "NO REPLY";
$email = $_POST["city"];
$phone = $_POST["email"];
$website = $_POST["phone"];
$message = $_POST["message"];
$header = "from: $name <$email>";
$to = 'info#mishmihillsadventure.in';
$send_contact=mail($to,$subject,$message,$header);
//Check, if message sent to your email
// Display message "We've recived your information"
if($send_contact){
echo "We've received your contact information";
}
else{
echo "ERROR";
}
?>
$email = $_POST["city"];
$phone = $_POST["email"];
Is this really what you want? Shouldn't it be:
$email = $_POST["email"];
And try the following headers:
$header = 'From: ' . $name . '<' . $email . '>' . "\r\n";
Use (atmost) following headers while sending mail via PHP -
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$header .= "From: $name <$email>" . "\r\n";
//If want to `CC` someone add
$header .= 'Cc: abc#email.com' . "\r\n";
Using variables in Double quotes is fine.
You can try something like in code mentioned below,
<?php
$to = 'test#to.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: test#from.com' . "\r\n" .
'Reply-To: test#from.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
echo 'Msg send..';
} else {
echo 'Msg Not send..';
}
?>