I am trying to set up sending a pdf attachment with mPDF and PHPMailer.
mPDF is woking fine when output is download to browser, the minute I change it to Output('',S) the code stops working with Error 500 and I have tried different versions of the mailer code with no luck. I cant find any error with the syntax and all online tutorials seem to agree with the code. I am stumped
My code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once __DIR__ . '/vendor/autoload.php';
// Grab variables
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$message = $_POST['message'];
$mpdf = new \Mpdf\Mpdf();
$data = "";
$data .= "<h1>Testing this</h1>";
//Add Data
$data .='<strong>First Name</strong> '. $fname.'<br>';
$data .='<strong>Last Name</strong> '. $lname.'<br>';
$data .='<strong>Email</strong> '. $email .'<br>';
if($message)
{
$data .='<br/><strong>Message</strong><br/> '. $message.'<br>';
}
//WritePdf
$mpdf->WriteHtml($data);
//output to bowser
$pdf = $mpdf->output('',S);
$enquirydata = [
'First Name' => $fname,
'Last Name' => $lname,
'Email' => $email,
'Message' => $message
];
sendEmail($pdf,$enquirydata);
function sendEmail($pdf, $enquirydata)
{
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'in-v3.mailjet.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('myemails#gmail.com', 'Test Form');
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
// Attachments
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>
If you are in a localhost, comment the line with the validation $email->isSMTP();
It works for me in my local.
Hello guyz i have create small kind of application in codeigniter,in this application i am doing forgot password module, i have created a function but dont know why its not working, i need random password have to been send in mail which will be autogenerated , but email method does not work, so give me some suggestion.
Here is My view:
<form action="<?php echo base_url() . "welcome/forgotpassword" ?>" method="POST">
<div class="form-group has-feedback">
<input type="email" class="form-control" placeholder="Email" name="user_email" />
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-4">
<input type="submit" class="btn btn-primary btn-block btn-flat" value="Send">
</div>
</div>
</form>
Here is my Controller:
public function forgotpassword(){
$email = $this->input->post('user_email');
$findemail = $this->main_model->ForgotPassword($email);
$this->load->view('forgotpassword');
if ($findemail) {
$this->main_model->sendpassword($findemail);
} else {
$this->session->set_flashdata('msg', 'Email not found!');
}
}
Here is My model:
public function sendpassword($data) {
$email = $data['user_email'];
print_r($data);
$query1 = $this->db->query("SELECT * from user_registration where user_email = '" . $email . "'");
$row = $query1->result_array();
if ($query1->num_rows() > 0) {
$passwordplain = "";
$passwordplain = rand(999999999, 9999999999);
$newpass['user_password'] = md5($passwordplain);
$this->db->where('user_email', $email);
$this->db->update('user_registration', $newpass);
$mail_message = 'Dear ' . $row[0]['full_name'] . ',' . "\r\n";
$mail_message .= 'Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>' . $passwordplain . '</b>' . "\r\n";
$mail_message .= '<br>Please Update your password.';
$mail_message .= '<br>Thanks & Regards';
$mail_message .= '<br>Your company name';
require FCPATH . 'assets/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = "tls";
$mail->Debugoutput = 'html';
$mail->Host = "ssl://smtp.googlemail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "xxxxxxxxx#gmail.com";
$mail->Password = "xxxxxxxx";
$mail->setFrom('xxxxxxx#gmail.com', 'admin');
$mail->IsHTML(true);
$mail->addAddress('user_email', $email);
$mail->Subject = 'OTP from company';
$mail->Body = $mail_message;
$mail->AltBody = $mail_message;
if (!$mail->send()) {
$this->session->set_flashdata('msg', 'Failed to send password, please try again!');
} else {
echo $this->email->print_debugger();
$this->session->set_flashdata('msg', 'Password sent to your email!');
}
}
}
This function may have something to do with it... can you show us that?
$findemail = $this->main_model->ForgotPassword($email);
When you use print_r($data) is anything returned?
If not, $query1 will be 0 or null and everything will break.
// core function
public function sendpassword($data) {
// include your libary at the top
require FCPATH . 'assets/PHPMailer/PHPMailerAutoload.php';
// email retrieved from the ForgotPassword() method.
$email = $data['user_email'];
// get the user_info array row
$query1 = $this->db->query("SELECT * from user_registration where user_email = '" . $email . "'");
$row = $query1->result_array();
if ($query1->num_rows() > 0) {
// assign users name to a variable
$full_name = $row['full_name'];
// generate password from a random integer
$passwordplain = rand(999999999, 9999999999);
// encrypt password
$encrypted_pass = $this->pass_gen($passwordplain);
$newpass['user_password'] = $encrypted_pass;
// update password in db
$this->db->where('user_email', $email);
$this->db->update('user_registration', $newpass);
// begin email functions
$result = $this->email_user($full_name, $email, $passwordplain);
echo $result;
}
}
// email sending
public function email_user($full_name, $email, $passwordplain) {
// compose message
$mail_message = 'Dear ' . $full_name. ',' . "\r\n";
$mail_message .= 'Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>' . $passwordplain . '</b>' . "\r\n";
$mail_message .= '<br>Please Update your password.';
$mail_message .= '<br>Thanks & Regards';
$mail_message .= '<br>Your company name';
// email config
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = "tls";
$mail->Debugoutput = 'html';
$mail->Host = "ssl://smtp.googlemail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "xxxxxxxxx#gmail.com";
$mail->Password = "xxxxxxxx";
$mail->setFrom('xxxxxxx#gmail.com', 'admin');
$mail->IsHTML(true);
$mail->addAddress('user_email', $email);
$mail->Subject = 'OTP from company';
$mail->Body = $mail_message;
$mail->AltBody = $mail_message;
// send the mail
if (!$mail->send()) {
return $this->email->print_debugger();
$this->session->set_flashdata('msg', 'Failed to send password, please try again!');
} else {
return $this->email->print_debugger();
$this->session->set_flashdata('msg', 'Password sent to your email!');
}
}
// Password encryption
public function pass_gen($password) {
$encrypted_pass = md5($password);
return $encrypted_pass;
}
$query1 = $this->db->query("SELECT * from user_registration where user_email = '" . $email . "'");
it is has sql injection!
So I've been following through various tutorials and documents to get this working and am really struggling. These are the files required for it to work:
Required Files
auth.php
<?php
session_start();
$config['base_url'] = '';
$config['callback_url'] = '';
$config['linkedin_access'] = '';
$config['linkedin_secret'] = '';
include_once "linkedin.php";
# The first step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback.
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;
# Now we retrieve a request token. It will be set as $linkedin->request_token.
$linkedin->getRequestToken();
$_SESSION['requestToken'] = serialize($linkedin->request_token);
# With a request token in hand, we can generate an authorization URL, which we'll direct the user to.
//echo "Authorization URL: " . $linkedin->generateAuthorizeUrl() . "\n\n";
header("Location: " . $linkedin->generateAuthorizeUrl()); ?>
demo.php
This is the script that I get after signup:
<?php
session_start();
$config['base_url'] = 'http://xxx/linkedin/auth.php';
$config['callback_url'] = 'http://xxx/linkedin/demo.php';
$config['linkedin_access'] = '';
$config['linkedin_secret'] = '';
include_once "linkedin.php";
# The first step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback.
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true; if (isset($_REQUEST['oauth_verifier'])){
$_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier'];
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
header("Location: " . $config['callback_url']);
exit;} else{
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->access_token = unserialize($_SESSION['oauth_access_token']);}
# You now have a $linkedin->access_token and can make calls on behalf of the current member.
$xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url)");
$id = $linkedin->getProfile('~:(id)');
$fname = $linkedin->getProfile('~:(first-name)');
$lname = $linkedin->getProfile('~:(last-name)');
$headline = $linkedin->getProfile('~:(headline)');
$picture = $linkedin->getProfile('~:(picture-url)');
$id = trim(strip_tags($id));
$fname = trim(strip_tags($fname));
$lname = trim(strip_tags($lname));
$headline = trim(strip_tags($headline));
$picture = trim(strip_tags($picture)); ?>
linkedin.php
This is linkedin library:
<?php require_once("OAuth.php"); class LinkedIn {
public $base_url = "http://api.linkedin.com";
public $secure_base_url = "https://api.linkedin.com";
public $oauth_callback = "oob";
public $consumer;
public $request_token;
public $access_token;
public $oauth_verifier;
public $signature_method;
public $request_token_path;
public $access_token_path;
public $authorize_path;
function __construct($consumer_key, $consumer_secret, $oauth_callback = NULL)
{
if($oauth_callback) {
$this->oauth_callback = $oauth_callback;
}
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret, $this->oauth_callback);
$this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->request_token_path = $this->secure_base_url . "/uas/oauth/requestToken";
$this->access_token_path = $this->secure_base_url . "/uas/oauth/accessToken";
$this->authorize_path = $this->secure_base_url . "/uas/oauth/authorize";
}
function getRequestToken()
{
$consumer = $this->consumer;
$request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path);
$request->set_parameter("oauth_callback", $this->oauth_callback);
$request->sign_request($this->signature_method, $consumer, NULL);
$headers = Array();
$url = $request->to_url();
$response = $this->httpRequest($url, $headers, "GET");
parse_str($response, $response_params);
$this->request_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}
function generateAuthorizeUrl()
{
$consumer = $this->consumer;
$request_token = $this->request_token;
return $this->authorize_path . "?oauth_token=" . $request_token->key;
}
function getAccessToken($oauth_verifier)
{
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->request_token, "GET", $this->access_token_path);
$request->set_parameter("oauth_verifier", $oauth_verifier);
$request->sign_request($this->signature_method, $this->consumer, $this->request_token);
$headers = Array();
$url = $request->to_url();
$response = $this->httpRequest($url, $headers, "GET");
parse_str($response, $response_params);
$this->access_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}
function getProfile($resource = "~")
{
$profile_url = $this->base_url . "/v1/people/" . $resource;
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $profile_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com"); # this is the realm
# This PHP library doesn't generate the header correctly when a realm is not specified.
# Make sure there is a space and not a comma after OAuth
// $auth_header = preg_replace("/Authorization\: OAuth\,/", "Authorization: OAuth ", $auth_header);
// # Make sure there is a space between OAuth attribute
// $auth_header = preg_replace('/\"\,/', '", ', $auth_header);
// $response will now hold the XML document
$response = $this->httpRequest($profile_url, $auth_header, "GET");
return $response;
}
function setStatus($status)
{
$profile_url = $this->base_url . "/v1/people/~";
$status_url = $this->base_url . "/v1/people/~/current-status";
echo "Setting status...\n";
$xml = "<current-status>" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "</current-status>";
echo $xml . "\n";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "PUT", $status_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$response = $this->httpRequest($profile_url, $auth_header, "GET");
return $response;
}
# Parameters should be a query string starting with "?"
# Example search("?count=10&start=10&company=LinkedIn");
function search($parameters)
{
$search_url = $this->base_url . "/v1/people-search:(people:(id,first-name,last-name,picture-url,site-standard-profile-request,headline),num-results)" . $parameters;
//$search_url = $this->base_url . "/v1/people-search?keywords=facebook";
echo "Performing search for: " . $parameters . "<br />";
echo "Search URL: $search_url <br />";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$response = $this->httpRequest($search_url, $auth_header, "GET");
return $response;
}
function httpRequest($url, $auth_header, $method, $body = NULL)
{
if (!$method) {
$method = "GET";
};
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header)); // Set the headers.
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header, "Content-Type: text/xml;charset=utf-8"));
}
$data = curl_exec($curl);
curl_close($curl);
return $data;
}}
The Problem
Trying to set the status
To set the status update I have tried using this in the demo.php file:
$setStatus = "Testing API";
$statusResponse = $linkedin->setStatus("~:($setStatus)");
echo '<pre>';
var_dump($statusResponse);
echo '</pre>';
But it is giving me this error:
Setting status... ~:(Testing API)
string(343) "
401
1407931633217
DW74ALZZVN
0
[unauthorized]. OAU:xxxxxxxxxxxxxxxxxx|xxxxxxxxxxxxx|*01|*01:1407931633:eyA6PiJzKUJixQLLtaQL90wppHI=
"
P.S: I x'd out the key there, but they are correct and the rest of the script works with them.
How do I set the status of the authorised account? So I've been following through various tutorials and documents to get this working and am really struggling. These are the files required for it to work:
Required Files
auth.php
<?php
session_start();
$config['base_url'] = '';
$config['callback_url'] = '';
$config['linkedin_access'] = '';
$config['linkedin_secret'] = '';
include_once "linkedin.php";
# The first step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback.
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;
# Now we retrieve a request token. It will be set as $linkedin->request_token.
$linkedin->getRequestToken();
$_SESSION['requestToken'] = serialize($linkedin->request_token);
# With a request token in hand, we can generate an authorization URL, which we'll direct the user to.
//echo "Authorization URL: " . $linkedin->generateAuthorizeUrl() . "\n\n";
header("Location: " . $linkedin->generateAuthorizeUrl()); ?>
demo.php
This is the script that I get after signup:
<?php
session_start();
$config['base_url'] = 'http://xxx/linkedin/auth.php';
$config['callback_url'] = 'http://xxx/linkedin/demo.php';
$config['linkedin_access'] = '';
$config['linkedin_secret'] = '';
include_once "linkedin.php";
# The first step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback.
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true; if (isset($_REQUEST['oauth_verifier'])){
$_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier'];
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
header("Location: " . $config['callback_url']);
exit;} else{
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->access_token = unserialize($_SESSION['oauth_access_token']);}
# You now have a $linkedin->access_token and can make calls on behalf of the current member.
$xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url)");
$id = $linkedin->getProfile('~:(id)');
$fname = $linkedin->getProfile('~:(first-name)');
$lname = $linkedin->getProfile('~:(last-name)');
$headline = $linkedin->getProfile('~:(headline)');
$picture = $linkedin->getProfile('~:(picture-url)');
$id = trim(strip_tags($id));
$fname = trim(strip_tags($fname));
$lname = trim(strip_tags($lname));
$headline = trim(strip_tags($headline));
$picture = trim(strip_tags($picture)); ?>
linkedin.php
This is linkedin library:
<?php require_once("OAuth.php"); class LinkedIn {
public $base_url = "http://api.linkedin.com";
public $secure_base_url = "https://api.linkedin.com";
public $oauth_callback = "oob";
public $consumer;
public $request_token;
public $access_token;
public $oauth_verifier;
public $signature_method;
public $request_token_path;
public $access_token_path;
public $authorize_path;
function __construct($consumer_key, $consumer_secret, $oauth_callback = NULL)
{
if($oauth_callback) {
$this->oauth_callback = $oauth_callback;
}
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret, $this->oauth_callback);
$this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->request_token_path = $this->secure_base_url . "/uas/oauth/requestToken";
$this->access_token_path = $this->secure_base_url . "/uas/oauth/accessToken";
$this->authorize_path = $this->secure_base_url . "/uas/oauth/authorize";
}
function getRequestToken()
{
$consumer = $this->consumer;
$request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path);
$request->set_parameter("oauth_callback", $this->oauth_callback);
$request->sign_request($this->signature_method, $consumer, NULL);
$headers = Array();
$url = $request->to_url();
$response = $this->httpRequest($url, $headers, "GET");
parse_str($response, $response_params);
$this->request_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}
function generateAuthorizeUrl()
{
$consumer = $this->consumer;
$request_token = $this->request_token;
return $this->authorize_path . "?oauth_token=" . $request_token->key;
}
function getAccessToken($oauth_verifier)
{
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->request_token, "GET", $this->access_token_path);
$request->set_parameter("oauth_verifier", $oauth_verifier);
$request->sign_request($this->signature_method, $this->consumer, $this->request_token);
$headers = Array();
$url = $request->to_url();
$response = $this->httpRequest($url, $headers, "GET");
parse_str($response, $response_params);
$this->access_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}
function getProfile($resource = "~")
{
$profile_url = $this->base_url . "/v1/people/" . $resource;
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $profile_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com"); # this is the realm
# This PHP library doesn't generate the header correctly when a realm is not specified.
# Make sure there is a space and not a comma after OAuth
// $auth_header = preg_replace("/Authorization\: OAuth\,/", "Authorization: OAuth ", $auth_header);
// # Make sure there is a space between OAuth attribute
// $auth_header = preg_replace('/\"\,/', '", ', $auth_header);
// $response will now hold the XML document
$response = $this->httpRequest($profile_url, $auth_header, "GET");
return $response;
}
function setStatus($status)
{
$profile_url = $this->base_url . "/v1/people/~";
$status_url = $this->base_url . "/v1/people/~/current-status";
echo "Setting status...\n";
$xml = "<current-status>" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "</current-status>";
echo $xml . "\n";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "PUT", $status_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$response = $this->httpRequest($profile_url, $auth_header, "GET");
return $response;
}
# Parameters should be a query string starting with "?"
# Example search("?count=10&start=10&company=LinkedIn");
function search($parameters)
{
$search_url = $this->base_url . "/v1/people-search:(people:(id,first-name,last-name,picture-url,site-standard-profile-request,headline),num-results)" . $parameters;
//$search_url = $this->base_url . "/v1/people-search?keywords=facebook";
echo "Performing search for: " . $parameters . "<br />";
echo "Search URL: $search_url <br />";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$response = $this->httpRequest($search_url, $auth_header, "GET");
return $response;
}
function httpRequest($url, $auth_header, $method, $body = NULL)
{
if (!$method) {
$method = "GET";
};
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header)); // Set the headers.
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header, "Content-Type: text/xml;charset=utf-8"));
}
$data = curl_exec($curl);
curl_close($curl);
return $data;
}}
The Problem
Trying to set the staus
To set the status update I have tried using this in the demo.php:
$setStatus = "Testing API";
$statusResponse = $linkedin->setStatus("~:($setStatus)");
echo '<pre>';
var_dump($statusResponse);
echo '</pre>';
But it is giving me this error:
Setting status... ~:(Testing API)
string(343) "
401
1407931633217
DW74ALZZVN
0
[unauthorized]. OAU:xxxxxxxxxxxxxxxxxx|xxxxxxxxxxxxx|*01|*01:1407931633:eyA6PiJzKUJixQLLtaQL90wppHI=
"
P.S: I x'd out the key there, but they are correct and the rest of the script works with them.
How do I set the status of the authorised account?
Not sure if it is still relevant, and the current-status API is deprecated, but the line:
$xml = "<current-status>" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "</current-status>";
needs to be changed to:
$xml = "" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "";
Please help me, i'm trying to send an email with an HTML body and a PDF-file attached. I'm using PHPMailer. I tried a lot but all I get in my mail is this:
--b1_422917e00bd74f108a49b5d3d858e74d Content-Type: text/html; charset = "iso-8859-1" Content-Transfer-Encoding: 8bit Hello World --b1_422917e00bd74f108a49b5d3d858e74d Content-Type: application/pdf; name="factuur.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="factuur.pdf" JVBERi0xLjQKJcfsj6IKMTEgMCBvYmoKPDwvTGVuZ3RoIDEyIDAgUi9GaWx0ZXIgL0ZsYXRlRGVj b2RlPj4Kc3RyZWFtCnic7VtZs9zEFa5A2CYpQyALSUiiNyQqI3pfeGOrOECgMJc8BPJg38Xbta8x NqbyL/Jn85yvF6mPpNbMXMoPVCrlskvT6j59+izfWdT+pmG9UA0Lf4aH43ubt69x2dz8dsOb8Ofh zY2zrGfeNU7yXmvf3Ns4wXrDxDhiHes50431vGdGlt8K741pjjfDiMEMbZuBgNHhp2qGLYbfxxvP fa+9Gke8CTOG9flXoT8MZAaG1QOD8yMcb87e2sieCwXST3DUj/D3Tj7ytb/8bx751uaLzTcNV1r3 0kVtcy5Vr3ijmeqNwFzfc+51tgLVfHCx+XwT7SMIRbMgsUAZkzkPlFygBCq2V83D00jfOZAUJtE3 eHamwSoBJhvJlOidzfR1or97iXAWm/i8xBy0xHLZDytsfYXoPV2hNes9z0tcWgKxKq5NMA8RVJCn QVzO6UjKaJxb6XTyJCa4yzcb1XNjjI0D9Pn4XvPeUdjBQ3Y9k841R2cb7OydlyJx1kBtTirbWA19 YuHRvc1X7U+6LYxJYR5vn+m2CprG6vbZbivCI7PtT8MM47znrn2uc2CTG9s+3215mKAUBiMJZYxv X+gkJoSnFzsMYnPVvtSJXjGtbfv1/W4re8cEF+3POg6FCWfan3cKTwxrvn4YqFrGNMd7Ft5z314Z 17+cGBROta9gI4ktOZ7+efQRzi5gN5CshLTL2fX87Er3GvYYz34NNITygrfXw3G5sKq9EQ6jpZRK thfkmY6X2ffJ6N2Os17ClNsmjAqDc6j2S+zhlJKifRSY98wb1z4Mj5Jr355CoFYLjB0noo6Z9lai et cetera..
I'm using this code:
$message = "<b>Hello World</b>";
$fromname = "Tester";
$subject = "Test - 3";
$headers = "Content-Type:text/html\n";
$to = "test#test.nl";
$attachment = $_SERVER['DOCUMENT_ROOT'] . "/facturen/test.pdf";
$mail = new PHPMailer();
$body = preg_replace('/\[\]/',"",$message);
$mail->IsSMTP();
$mail->Host = "smtp.test.nl";
$mail->SMTPAuth = true;
$mail->Host = "smtp.test.nl";
$mail->Port = 25;
$mail->Username = $user;
$mail->Password = $pass;
$mail->IsHTML(true);
$mail->SetFrom($user, $user);
$mail->FromName = $fromname;
$mail->Subject = $subject;
$mail->Body = $body;
$mail->addCustomHeader($headers);
$address = $to;
$mail->AddAddress($address, $address);
$mail->AddAttachment($attachment, "factuur.pdf", $encoding = 'base64', $type = 'application/pdf');
if(!$mail->Send()) {
echo "Fout";
} else {
echo "Goed";
}
Anyone an idea how to resolve this?
try removing:
$body = preg_replace('/\[\]/',"",$message);
and
$headers = "Content-Type:text/html\n";
When I send the email with html tags.Gmail shows the tags also.Why is that? any solution?how to ad images bold text colored text according to my code?
here is my email content code
smtpmailer("$email", 'website#yahoo.com', '<html><body>website.lk Password recovery', 'Password recovery','Dear "'.$name."\"\n\nUse your new password to login and reset your password as you wish.\nTo reset password go to your \"My Account\" page and click \"Change my password\"\n\n"."Here is your new password:\n\n"."Password: "."$password"."\n\nBack to get bump: www.website.lk\n\nRegards,\n website.lk Admin\n</body></html>");
$reset_msg="Recovery completed. Check your e-mail !";
}else{
$reset_msg="Error in sending email.Try again !";
}
By including the below headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
Source,
http://php.net/manual/en/function.mail.php
if you are using PHP Mailer,
$mail->MsgHTML($body);
$mail->AddAttachment("images/image1.gif");
$mail->AddAttachment("images/image2.gif");
if you are using this function:
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
Then change the line of $mail->Body = $body; to code blow:
$mail->MsgHTML($body);
This change will allow you to send HTML emails via PHPMailer, You can also add $mail->CharSet = 'UTF-8'; to avoid future problems with special characters ...
Use $mail->IsHTML(ture);
If on phpmailer..