I use PHPMailer to send email via SMTP. It works, but it doesn't save the sent emails in
sent items. I want to make to sent emails in the sent items, any idea?
I know can use imap_append function to achieve it. But, how to do that?
The PHPMailer seems doesn't has the function to return the $message.
if ($return = $mail->Send()) {
$stream = imap_open("{{$host}:993/imap/ssl}Sent Items", $user_name, $user_pwd);
imap_append($stream, "{{$host}:993/imap/ssl}Sent Items" , $message , "\\Seen");
imap_close($stream);
};
How to get the message body from PHPMailer?
The instance variables from PHPMailer are all public.
Looking at the source you can just use:
$mail->Body
If you want the plain body including the all boundaries you could also use:
$mail->CreateBody();
See:
http://phpmailer.svn.sourceforge.net/viewvc/phpmailer/trunk/phpmailer/class.phpmailer.php?revision=452&view=markup
The PHPMailer seems doesn't has the function to return the $message.
Yes, it does. At least in version 5.2.28 there is a method getSentMIMEMessage() to get the full MIME message (different from the email body). That method only works after sending the email, or calling the preSend() method.
Related
When I send an email using phpmailer to gmail, and I look the email source, I see the following next to the "from" field:
"Using PHPMailer 6.1.7 (https://github.com/PHPMailer/PHPMailer)"
For security reasons I'd prefer to remove that if it's possible, but I don't know if this is Gmail being smart or phpmailer appending it to every email message I send.
How can I remove it?
Thanks
This appears in the X-Mailer header. As per the docs, you can remove this header altogether by setting it to a space, like this:
$mail->XMailer = ' ';
If it's appearing somewhere else, I'll need to see the rest of your code and the headers of a message you've received in gmail.
I am newbie with PHPMailer library , I want to get emails from my contact form But on submission of form I want sender also get a copy of mail With additional message as " thanks for registering with us." As I gone through PHP mailer examples We can use addCC();. But how to embed additional msg.
Could you please help me with this ?
Using CC or BCC will always result in identical message being sent to all; If you want the messages to be different for different recipients, you must send separate messages with different bodies. With PHPMailer:
$mail->addAddress('recipient1#example.com');
$mail->Body = "hello abc";
$mail->send();
$mail->clearAddresses();
$mail->addAddress('recipient2#example.com');
$mail->Body = "hello xyz";
$mail->send();
It's important to call clearAddresses as otherwise the second message will be sent to both recpients.
I have a situation where I sending an 2 different emails, one to a customer and one to a member after the member accepts a task. Within the function I am calling 2 functions, one that sends to the client and one is sent to the member. The what is happening is that the second email is being sent to both the member and the client, yet the client, the first email, only gets the email expected.
What I figured is happening is that because both of these functions are occurring at the same time, some how the addAddress() function is taking both email addresses over to the second email. My proof of this is I changed the order of the functions so the Member send first and the Client sent second and they both got the Client email where before the Client sent first and the Member sent second.
My question than is how do I make the first email break for a few seconds before the second email is sent to stop this from happening.
Here is the basic set up of the code.
function memberAccept()
{
// SQL to mark in DB that member accept task
$this->memberEmail($id)
$this->clientEmail($id)
}
function memberEmail($id)
{
// SQL to gather information about member inner join with task
$subject = 'Email';
$body = 'Email to member'
$this->sendEmail($member['email'], $subject, $body)
}
function clientEmail($id)
{
// SQL to gather information about client inner join with task
$subject = 'Email';
$body = 'Email to client'
$this->sendEmail($client['priemail'], $subject, $body)
}
sendEmail() is in another Class set up to use PHPMailer functions to send the email.
In your case, you must use the following function before adding new recipient for the mail:
$mailer->ClearAllRecipients( ); // clear all
Basically, the problem is that, when you add first recipient, mailer successfully delivers the mail, but the object is not destroyed yet. Hence, when the next mail is sent, member's email is still in the recipient, so alter your code to call this ClearAllRecipients function before adding the new recipient.
I am trying to send email using SMTP in Laravel everything is good but the html elements is coming along in the email body.
i.e.,
I am getting the below as mail
<h2>Welcome</h2><br><p>Hello user</p><br><p>Thanks</p>
Instead of
WelcomeHello userThanks
Here is my Code :
What is the thing i am missing to make it applied on the content of the email
$msg = "<h2>Welcome</h2><br><p>Hello user</p><br><p>Thanks</p>"
$message->setBody($msg);
$message->to('user#gmail.com');
$message->subject('Welcome Mail');
Try this...
$msg = "Welcome
Hello user
Thanks"
$message->setBody($msg);
$message->to('user#gmail.com');
$message->subject('Welcome Mail');
One possible solution is to wrap your HTML code in body tag.
Take a look at Laravel mail api too.
Seems like you want to send an email as HTML format:
mail($to, $subject, $message, $headers);
You will have to use the $headers parameter.
The last parameter, the headers, are optional for the function but required for sending HTML email, as this is where we are able to pass along the Content-Type declaration telling email clients to parse the email as HTML.
Source
Or, if you just want to add breaking lines and you leave HTML elements:
$msg = "Welcome \n Hello user \n Thanks"
I am using the below code to can through my inbox:
$imap = imap_open("{imap.gmail.com:993/ssl}[Gmail]/ALL Mail", $yourEmail, $yourEmailPassword);
The thing is how to segregate between the sent mails and recieived mail?
I know I can use:
imap_open("{imap.gmail.com:993/ssl}[Gmail]/Sent Mail", $yourEmail, $yourEmailPassword);
imap_open("{imap.gmail.com:993/ssl}INBOX", $yourEmail, $yourEmailPassword);
But the thing I want to do this?
I want to extract mail using ALL MAIL and while iterating i should know if it is a sent or received?
Is there any way to do it?