How to make a email calendar invite automatically accepted (php)? - icalendar

I'm sending a calendar invite via email but I want it automatically be accepted.
Is there something I can change in my code? My code looks like this:
function sendIcalEmail ($firstname, $lastname, $email, $meeting_date, $meeting_name, $meeting_duration) {
$from_name = “My Name”;
$from_address = “myname#mydomain.com”;
$subject = “Meeting Booking”; //Doubles as email subject and meeting subject in calendar
$meeting_description = “Here is a brief description of my meeting\n\n”;
$meeting_location = “My Office”; //Where will your meeting take place
//Convert MYSQL datetime and construct iCal start, end and issue dates
$meetingstamp = strtotime($meeting_date . ” UTC”);
$dtstart= gmdate(”Ymd\THis\Z”,$meetingstamp);
$dtend= gmdate(”Ymd\THis\Z”,$meetingstamp+$meeting_duration);
$todaystamp = gmdate(”Ymd\THis\Z”);
//Create unique identifier
$cal_uid = date(’Ymd’).’T’.date(’His’).”-”.rand().”#mydomain.com”;
//Create Mime Boundry
$mime_boundary = “—-Meeting Booking—-”.md5(time());
//Create Email Headers
$headers = “From: “.$from_name.” <”.$from_address.”>\n”;
$headers .= “Reply-To: “.$from_name.” <”.$from_address.”>\n”;
$headers .= “MIME-Version: 1.0\n”;
$headers .= “Content-Type: multipart/alternative; boundary=\”$mime_boundary\”\n”;
$headers .= “Content-class: urn:content-classes:calendarmessage\n”;
//Create Email Body (HTML)
$message .= “–$mime_boundary\n”;
$message .= “Content-Type: text/html; charset=UTF-8\n”;
$message .= “Content-Transfer-Encoding: 8bit\n\n”;
$message .= “<html>\n”;
$message .= “<body>\n”;
$message .= ‘<p>Dear ‘.$firstname.’ ‘.$lastname.’,</p>’;
$message .= ‘<p>Here is my HTML Email / Used for Meeting Description</p>’;
$message .= “</body>\n”;
$message .= “</html>\n”;
$message .= “–$mime_boundary\n”;
//Create ICAL Content (Google rfc 2445 for details and examples of usage, beware of adding tabs)
$ical = ‘BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER:MAILTO:’.$from_address.’
DTSTART:’.$dtstart.’
DTEND:’.$dtend.’
LOCATION:’.$meeting_location.’
TRANSP:OPAQUE
SEQUENCE:0
UID:’.$cal_uid.’
DTSTAMP:’.$todaystamp.’
DESCRIPTION:’.$meeting_description.’
SUMMARY:’.$subject.’
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR’;
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST;charset=utf-8\n';
$message .= 'Content-Transfer-Encoding: 8bit\n\n';
$message .= $ical;
//SEND MAIL
$mail_sent = #mail( $email, $subject, $message, $headers );
if($mail_sent) {
return true;
} else {
return false;
}
}

Imho it is not or should not be possible to post an invite that automatically will be accepted. Instead you should inform your users that they can they can change their settings in Outlook to automatically accept (certain) invites.
Btw thanks for your snippet. Just what I needed.

Hi for calendar auto acceptance you should add the given lines in your code to create ics file.
ATTENDEE;PARTSTAT=ACCEPTED;CN= ExampleName1 c;EMAIL=example1#mail.com:MAILTO:example1#mail.com
ATTENDEE;PARTSTAT=ACCEPTED;CN= ExampleName2 c;EMAIL=example2#mail.comMAILTO:example2#mail.com

Related

How to reset user password by wordpress rest api

Any one of you know know to send a reset link for lost password by wordpress rest api ? I have been looking into wordpress rest api documentation but I haven't find out anything about it. Maybe someone has done a custom function for that.
I found out a way to do that:
function runRetrivePassword($data)
{
global $wpdb, $wp_hasher;
$user_data = get_user_by('email', $data['email']);
if (!$user_data) return array('result' => false);
do_action('lostpassword_post');
$user_login = $user_data->user_login;
$user_email = $user_data->user_email;
$key = get_password_reset_key($user_data);
$message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
$message .= network_home_url('/') . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
$message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
$message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');
if (is_multisite())
$blogname = $GLOBALS['current_site']->site_name;
else
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$title = sprintf(__('[%s] Password Reset'), $blogname);
$title = apply_filters('retrieve_password_title', $title);
$message = apply_filters('retrieve_password_message', $message, $key);
if ($message && !wp_mail($user_email, $title, $message))
wp_die(__('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...'));
return array('result' => true);
}
add_action('rest_api_init', function () {
register_rest_route('apiuser/v1', '/forgotpwd/(?P<email>\S+)', array(
'methods' => 'GET',
'callback' => 'runRetrivePassword'
));
});

FPDF PDF file cannot be opened after email using PHPMailer

I am trying to create a PDF file using FPDF and send it via e-mail using PHPMailer. It did send the file, but for some reasons I cannot open the file, either from my email or using Adobe Reader (which gives me something like the file is damaged).
This is my code
require('fpdf.php');
require 'PHPMailerAutoload.php';
header("Access-Control-Allow-Origin: *");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','UB',28);
$pdf->Cell(0,10,"My Profile",0,1,'C');
$pdf->Ln();
$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 = 'example#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
$pdfdoc = $pdf->Output('','S');
$attachment = chunk_split(base64_encode($pdfdoc));
//Set who the message is to be sent from
$mail->setFrom('example#gmail.com', 'Baby Diary');
//Set who the message is to be sent to
$mail->addAddress('example2#gmail.com', 'haha');
//Set the subject line
$mail->Subject = 'PHPMailer mail() test';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AddStringAttachment($attachment, 'doc.pdf', 'base64', 'application/pdf');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
It does give me output when I use $pdf->Output(), which hints to me that the problem should not be in FPDF side. Any suggestion will be much appreciated.
Your problem is with phpmailer and not with fpdf. Try using the standard PHPMailer class methods.
If I was you I'd try to rework your code from the attachement example included in the PHPMailer doc samples. And particularly I'd stick to using the PHPMailer methods rather that doing my own smtp formating.
So first save your pdf to file, and then try attaching the file with $mail->addAttachment() . And let PHPMailer handle the formating of the mail.
So you might end up with something like this code below (I haven't run it, you'll probably need to fine tune it) :
require('fpdf.php');
require 'PHPMailerAutoload.php';
header("Access-Control-Allow-Origin: *");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','UB',28);
$pdf->Cell(0,10,"My Profile",0,1,'C');
$pdf->Ln();
$pdfoutputfile = '/some-tmp-dir/temp-file.pdf';
$pdfdoc = $pdf->Output($pdfoutputfile, 'F');
// We're done with the pdf generation
// now onto the email generation
$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 = 'example#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
$separator = md5(time()); // a random hash will be necessary to send mixed content
//Set who the message is to be sent from
$mail->setFrom('example#gmail.com', 'From Test address');
//Set who the message is to be sent to
$mail->addAddress('example2#gmail.com', 'to test address');
//Set the subject line
$mail->Subject = 'Test message with attachement';
$mail->Body = 'Test message with attached files.';
$mail->AddAttachment($pdfoutputfile, 'my-doc.pdf');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

Reply-To header not picking the php variable

I am creating a page that sends the response from contact form within mail but reply-to is not working (the variable i am using is having value, but is not added within headers)
here's my code:
<?php
//$uname=$_REQUEST['uname'];
if(isset($_REQUEST['name']))
{
$name=$_REQUEST['name'];
}
if(isset($_REQUEST['email']))
{
$email=$_REQUEST['email'];
}
if(isset($_REQUEST['phone']))
{
$phone=$_REQUEST['phone'];
}
if(isset($_REQUEST['message']))
{
$message=$_REQUEST['message'];
}
// TESTING IF VARIABLES HAVE VALUES
echo "$name $email $phone $message";
// RESULT: TRUE TILL HERE
if($name=="" || $email=="" || $phone=="" || $message=="")
{
header("location:../?inst=invalid");
}
else
{
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to="mail#example.com";
// Your subject
$subject="$name Contacted you via Contact Form";
// From
$headers = "From: ME <no-reply#example.com>\r\n";
$headers .= 'Reply-To:' . $email . "\r\n";
$headers .= "Return-Path: info#example.com\r\n";
$headers .= "X-Mailer: PHP\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
print $message;
// send email
$sentmail = mail($to,$subject,$message,$headers);
//$sentmail = mail($to1,$subject,$message,$header);
}
// if your email succesfully sent
if($sentmail){
echo "Mail Sent.";
}
else {
header("location:../landing/?status=verification-pending");
}
?>
Now when i checked headers in my gmail, the value for $email doesn't appear in header information, Also no message is received. All I get is a blank message or may be $message is not printing anything like the same case i am facing with reply-to.
please help me a little with this. Thanks in advance.
Check that you have php warnings and notices enabled. When you are echoing out $name, $email, etc you are doing a redirect using headers after that. If your php notices etc aren't turned on, your header redirect will fail due to having already echoed something, and you won't know that you had invalid input. This is part of the reason you shouldn't echo things out during logic, but should store and out put values later.
Actually there was a little mistake with the above code. I mistakenly added = instead of == while comparison.
This line:
if($name=="" || $email="" || $phone="" || $message="")
Should read as:
if($name=="" || $email=="" || $phone=="" || $message=="")
Since = is for equation and not a condition for comparison ==
Fixed it in the Question

properly setting email subject line delivered from email form

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.

How do I use LinkedIn API with Zend_OAuth?

I'm writing a class wrapper for LinkedIn API and I'm using Zend Framework 1.11.2. Here is a snippet I have:
$config = Pb_Portal::getInstance()->getConfig('linkedin.ini');
$body = '<?xml version="1.0" encoding="UTF-8"?>';
$body .= '<share>';
$body .= '<comment>83% of employers will use social media to hire: 78% LinkedIn, 55% Facebook, 45% Twitter [SF Biz Times] http://bit.ly/cCpeOD</comment>';
$body .= '<content>';
$body .= '<title>Survey: Social networks top hiring tool - San Francisco Business Times</title>';
$body .= '<submitted-url>http://sanfrancisco.bizjournals.com/sanfrancisco/stories/2010/06/28/daily34.html</submitted-url>';
$body .= '<submitted-image-url>http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg</submitted-image-url>';
$body .= '</content>';
$body .= '<visibility>';
$body .= '<code>anyone</code>';
$body .= '</visibility>';
$body .= '</share>';
$client = Zend_Oauth::getHttpClient();
$client->setUri('http://api.linkedin.com/v1/people/~/shares');
$client->setMethod(Zend_Http_Client::POST);
$client->setRawData($body,'text/xml');
$client->setHeaders('Content-Type', 'text/xml');
$client->setParameterPost('oauth_consumer_key', $config->appKey);
$client->setParameterPost('oauth_nonce', $config->appSecretKey);
$client->setParameterPost('oauth_token', $acc->getToken());
$client->setParameterPost('oauth_timestamp', time());
$client->setParameterPost('oauth_signature_method', 'HMAC-SHA1');
$client->setParameterPost('oauth_version', '1.0');
$response = $client->request();
$xml = #simplexml_load_string($response->getBody());
And I have this response:
SimpleXMLElement Object
(
[status] => 401
[timestamp] => 1299581073233
[error-code] => 0
[message] => Unknown authentication scheme
)
Can somebody help me? Where I go wrong?
I had a similar problem (although I am just retrieving user info). This link helped a great deal. Instead of constructing the params as get variables, you allow the token to construct the http client from your options.
http://www.contentwithstyle.co.uk/content/linkedin-and-zendoauth/
You may need to change the way you are writing class wrapper.
You can take idea from this post and accepted answer there!!
Linkedin: How to make api calls using access token?
best of luck