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');
Related
I am trying to send emails to a team and some invited individuals to indicate their assigned cooperation. However, only the first recipient (the team) in the $to seems to be receiving an email. The invited individuals do not receive any emails. Can anyone tell what I did wrong?
<?php
/* Template Name: send emails */
include_once ('important.php');
function get_emails($campus) {
global $mydb;
$individuals = array();
$individuals = $mydb->get_results("SELECT * FROM individuals WHERE campus = '$campus'");
return array_map(function($e) {
return $e->individual_email; }, $individuals);
}
$team_email = 'teamA#gmail.com';
$campus = 'NY';
$individuals = get_emails($campus);
$to = $team_email. ', ' .implode(', ', $individuals);
$subject = 'Team invitation from ' . $team_email. '!';
$message = 'Hello everyone, you are now working together';
send_email($message, $subject, $to);
function send_email($message, $subject, $to, $from='admin#gmail.com', $from_name='Admin Team Creator') { $message = '';
$message .= '<html>';
$message .= '<body>';
$message .= $msg;
$message .= '-<br/>';
$message .= '<font face="tahoma, sans-serif" color="#0eafd6"><b>The Admin Team Creator</b></font><br/>';
$message .= '</body>'; $message .= '</html>';
$headers = ''; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: ' . $from . ' <' . $from_name . '>' . "\r\n" . 'Reply-To: ' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
return mail($to, $subject, $message, $headers, '-f ' . $from); }
?>
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);
I have such code for send email:
$email = $_POST['message_email'];
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
before that I check whether the email is correct so it has to be.
Then I send an email:
$sent = wp_mail($newTo, $subject, $companyName . "\n" . $email . "\n" . $phoneNumber . "\n" . strip_tags($message) . "\n" . $outputMail, $headers);
and it doesn't work. I've tried change headers to:
$headers = 'From: My Name <myname#mydomain.com>' . "\r\n\\";
and then it works. Why my code does't work? I need to provide that email retreived from form.
Try like this:
****Ive edited the code****
$from = "your#mail.com";
$to = "to#mail.com";
$message = "Message";
$subject = 'subject';
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
if(mail($from, $subject, $message, $headers)){
//success
}else{
//error
}
Can anyone think of a logical reason to why a contact form which works perfectly well on my 123 reg account, will not work on my clients account? when I test it on my side, I get the email and the form contents through to my inbox perfectly but when the same codes are used on my clients account, with his email address, he receives an email with no data..
<?php
$EmailFrom = "webmaster#pb.co.uk";
$EmailTo = "loans#website.co.uk";
$Subject = "Testing";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "eMail: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://website/thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
change
"From: $EmailFrom"
to
"From: $EmailFrom" . "\r\n"
Add header.
$Body = 'MIME-Version: 1.0' . "\r\n";
$Body .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$Body .= 'From: '. $EmailFrom . "\r\n" . 'X-Mailer: PHP/' . phpversion();
I am having problems with this contact page, emails are being sent fine but are blank! I cant seem to find a solution. I would of thought $_POST would need to be added, however, the web hosting companies says it is not necessary in this php script Thankyou for your time and help. Code snippet below.
<?php
$EmailFrom = "sales#ibdengland.co.uk";
$EmailTo = "kent.collins.uk#gmail.com";
$Subject = "online form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Message = Trim(stripslashes($_POST['Description of project']));
// validation
$validationOK=true;
if (!$validationOK) {
echo "please check your details";
header("Location: http://www.ibdengland.co.uk/thankyou.html");
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Description of project: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
?>
You forgot to add the headers.
Example:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '. $EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Try changing:
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
To:
$success = mail($EmailTo, $Subject, $Body, "From: <".$EmailFrom.">");
you have not use any header.
take help from here. and use it. I think it will help you.
post header like below
$headers = 'From:'.$EmailFrom . "\r\n" .
'Reply-To: '.$EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();
then replace below
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
with the below code
$success = mail($EmailTo, $Subject, $Body, $headers);
plz try this one. and inform me if this work or not.