Differentiating between sent and received mail - php

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?

Related

Can't embed variable in mail function php

I want to send email with different subjects. I have the following code that get mail subject and message from the database.
$sql = "SELECT mail_subject, mail_content FROM new_business WHERE business_name = '$biz_name'";
$query = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($query)) {
$subject = $row['mail_subject']; //Getting mail subject to send
$mail_content = $row['mail_content']; //Getting mail content
}
echo $subject; //checking if it gets subject and it surely does.
$to = 'utopian51#gmail.com';
mail($to, $subject, $mail_content);//Mail is not sent
If subject pulls data from database mail is not sent. I have checked several times including spam and also checked if subject gets any data from database before embedding it in mail function. It seems it gets the right data but the mail is not sent.
But when i hardcode the subject like this: $subject = 'this is a test subject'; , the mail is sent successfully. Why mail function does not let me embed variable that gets subject from database? I need to send the mails with different subject from database. Whats the solution?
There's many things which are confusing about the code you've written. You never check for error conditions in the mysqli_ calls nor the mail() call. You run a query which will discard all but the last row (if any). However the way to diagnose issues with mail() is not to watch your inbox. In more than 99% of cases the problem is with the interface between PHP and the MTA or with the MTA configuration itself.
You have provided no details of either.
I would recommend you use simply:
mail('utopian51#gmail.com', 'test', date('r'));
and start debugging your MTA.
Independently you can work on your bulk emailing script, simply writing to a file instead of calling mail() until both parts are working.

email are not shown up as conversion when Parsed with php imap and sending back to sender

hi I'm working with php imap functionality,
I'm parsing mails from my mail box and storing them into mysql,:
i'm storing following information:
From
To
Subject
Content
Time of receiving mail
After one hour I'm sending back this mail. for sending mail i'm using ses mail of amazon.
I create a mail using the saved data and sending them to my gmail again.
But it is not showing up as group or conversion in gmail.
Here is my code for sending mail:
function sendEmail($pendingMail) {
$sesAccUserName = 'noreply#mydomain.com';
$ses = new AmazonSES(array("key" => AWSAccessKeyId, "secret" => AWSSecretKey));
$source = trim($sesAccUserName);
$destination = array('ToAddresses' => array(trim($pendingMail['email_reminder_send_to_address'])));
$messageBody = $pendingMail['email_reminder_content'];
$messageSubject = $pendingMail['email_reminder_subject'];
$messageArr = array('Subject.Data' => 'Fwd: '.$messageSubject, 'Body.Html.Data' => $messageBody);
$rSendEmail = $ses->send_email($source, $destination, $messageArr);
if ($rSendEmail->status == 200) {
changeStatus($pendingMail['email_reminder_id'], 'completed');
} else {
print_r($rSendEmail);
}
}
Mail sent successfully but it is not grouped with the original message?
I think i googled a lot but not find anything useful..
I'm at beginner level about emails...
will you help me to solve this issue...
Thank you !!!!!!!!!!
I research some gmail inbox mails and found that each mail have a message-id in header,
When we reply to mail the value of message-id is set to a header field In Reply To: of the reply mail (the mail we are sending in reply).
This message-id and In Reply To are responsible for grouping of message in gmail...

How to get the message body from PHPMailer?

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.

having a php page send an email

This question should have a simple, simple answer, but I just can't seem to get it working. Here's the scenario:
I created a php page -> this one: http://adianl.ca/pages/member_application.php. Once the form is completed, it proceeds to http://adianl.ca/pages/member_application_action.php, puts the data into a MySQL db, & thanks the user for their interest. Anyway, the form works perfectly, except for one little thing: whenever someone fills out that form, I want an email to be sent to sbeattie#adianl.ca, informing them that the form was filled out, & the email would include the form components. The problem is, I can NOT get an email to be sent to that address, or any address truth be told. Having a php page send an email should be a simple thing to do, but it's really baffling me.
Can anyone help me with this? This particular problem has been troubling me since yesterday, & if anyone can help me with this...man, thank you soooooo much.
JP
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.adianl.ca"; // SMTP server $mail->From = "webadmin#adianl.ca";
$mail->FromName = "Web Administration [ADIANL]";
$mail->AddAddress("sbeattie#adianl.ca");
$mail->AddCC("justinwparsons#gmail.com"); the #messageBody variable is just a string
If you want to have the email sent using the server's sendmail client, you can use mail.
If you want it to use another mail server, there are extensions to connect to an SMTP server. I use PHPMailer.
If mail doesn't work, it could be that the server is not set up to send email, or it could be that the mail server is rejecting emails sent from php, amongst other reasons.
this code can also be used to email in php so have a look, you can find many more examples of emailing in php look around
?php
$to = "recipient#example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}

which of this method is recomended - mail function

hay
now i want to send mail to 200 users
first way
$users = 'user1#,user2#,user3,etc';
foreach(explod(',',$users as $mail){
mail($mail,'','','');
}
or
mail(mail one,mail 2,mail3,mail4,etc)
i know the code is fully error
but i want the meaning
which is the best
mail with multi by spreate by ,
or looping the mail function with the one mail every time
Ideally, you should use an external piece of mailing software so you can send an e-mail to a list and it will handle individual recipients; this way, you can avoid looping mail calls (and queued sendmail requests) while not disclosing your mailing list.
Of the options you presented, it is best to send your email using a loop with individual calls to the mail function so as not to disclose your recipients.
Finally, maybe try something like this:
$recipients = array('user#example.com','admin#example.org',); // mail list
$bcc = join(',', $recipients);
mail(
'"Undisclosed Recipients" <no-reply#example.com>',
$subject,
$message,
"BCC: {$bcc}"
);
However, if you are using this, make sure whatever sendmail client you are using strips the BCC header before sending.

Categories