Get Webhook PHP and send by email - php

I have created a PHP file that receives webhook notifications and writes them to a TXT file but I also want to receive them via email so I added the send email function but it doesn't work because there is a bug in testing. When I remove the lines "mail("my#email.eu","NEW MSG","$json");" it works without errors, so did I do something wrong? Please help.
<?php
$headers = "X-Event-Name: product.update";
$headers = "X-Event-Secret: my_key";
$json = file_get_contents("php://input");
file_put_contents('log.txt', "$json", FILE_APPEND | LOCK_EX);
mail("my#email.eu","NEW MSG","$json");
http_response_code(204);

Related

E-mail piping with e-mail forwarder does not work

I have a simple email pipe script. But I need a copy of the incoming e-mail going to another e-mail address. Unfortunately I do not receive the e-mail as I wanted.
The code;
#!/usr/bin/php -q
<?php
$email_msg = ''; // the content of the email that is being piped
$email_addr = 'sales#flensmuts.nl'; // where the email will be sent
$subject = 'Piped:'; // the subject of the email being sent
// open a handle to the email
$fh = fopen("php://stdin", "r");
// read through the email until the end
while (!feof($fh)){
$email_msg .= fread($fh, 1024);
}
fclose($fh);
// send a copy of the email to your account
mail($email_addr, $subject, "Piped Email: ".$email_msg);
?>
Your mail server logs will probably say something about this. My guess is that it might be failing because your message is malformed because of the prefix you're adding. Try sending the message untouched, like this:
mail($email_addr, $subject, $email_msg);
Separately, for simple forwarding like this, you can probably set up your mail server to do this directly without having to go via a script.
There is no error checking in your script. There is no instrumentation in your script to see if it is even being run. You have not said why you believe that the script is being triggered. You have not said how mail() works on your test site.
Decompose the issues. Replace this script with one which dumps stein to a file to find out if there is an issue with the input integration.
Write and run a script which sends an email when using mail() when manually invoked. If you control the MTA then read your logs - even if these experiments are successful.
Then go back to your original script. Add some logging. Check the value returned by mail(). Check that the delivery path accepts forwarded mail with a broken envelope.

Modifying & Relaying Mail

Is there any way to simply relay mails received by a PHP script? Instead of being received normally into a mailbox, I have routed all incoming mails to a PHP script that would parse and log them (from, subject, message text) into a text file.
This is the truncated version of the script:.
<?php
$feed = fopen ("php://stdin", 'r');
$email = '';
while (!feof($feed))
{
$email .= fread($feed, 1024);
}
fclose($feed);
$to = explode...
$from = explode..
$subject = explode...
$message = utf8_encode...
$log = fopen("/home/.../log.txt", "a+");
fwrite($log,...);
fclose($log);
?>
Would it be possible to relay the entire message, as is, to another recipient, but not as a forward?
TIA.
Apparently, the email is received with a whole bunch of additional headers, from the original sender. So, it must be parsed, and only the required headers extracted and used. The relevant header entries could also be modified to change the sender & recipient information, as well as the subject. Once all that is done, the PHP mail() function could be used to re-send the email.
Simple, and it works. The only drawback is that GMail keeps reporting that the sender cannot be confirmed as the actual sender (or spammer).

how to Send HTML form data as PDF file from database via email function?

I am new in php and i am working on my own project in which i have a html form.
When a user fills the form and clicks on submit all the data in form will store in database and also all data send to admin/owner in PDF formate via email.
I successfully store the data in database but, I don't know how could i send a pdf file via email..
I have tried the following code.
$to = 'example#email.com';
$subject = "Website Form Data Email";
$txt = $name .' '. $addr .' '. $snpno.' ;
$headers = "" . "\r\n" .
mail($to, $subject, $txt, $headers);
Please help me.
Thanks All...
*First you have to generate pdf file. *You can search in google and find some pdf generation plugin for php. Use one of them and create pdf file *And then use php mail to send mail with attachment. Here some code for Send attachments with PHP Mail()

How to save an Email attachment as an Email message?

I am pretty new when it comes to handling emails in php.
Basically I need to read a pop3 mailbox and save the messages to a database and the attachments to a folder. Then mail that same mail (slightly altered) back to another email recipient.
I thought I got this all working, then I realized when the attachment is another mail message I only receive the body as text (after base64_decode).
Is it possible to save an attached email to a file and then send it as attachment in another message?
Any help will be appreciated.
Here is some code to put it into perspective :
// This is the IMAP connection: imap_open("{"."$host:$port/pop3$ssl"."}$folder",$user,$pass,OP_SILENT);
$mailConnection = $this->Maildata->mail_login($host,$port,$user,$pass,$folder,$ssl);
// This retrieves the list of mails in the current folder
$messageList = $this->Maildata->mail_list($mailConnection,$message);
foreach ($messageList as $messageId => $messageListData) {
// This reads the mail object into an array
$mailMessage = $this->Maildata->mail_mime_to_array($mailConnection,$messageId,true);
// This loops through each mail
foreach ($mailMessage as $tmpId => $tmpData) {
// Excluded save to database since it is unrelated
// This checks if item is an attachment and saves it.
if (isset($tmpData['is_attachment']) && $tmpData['is_attachment'] === true) {
$tmpName = date('Y-m-d H:i:s', strtotime('now'));
$this->Maildata->mail_attachment_save($tmpData['data'], $tmpName .$tmpData['name']);
}
}
}
P.S. This all works, but imap_fetchbody($mailConnection , $messageId, $prefix); doesn't seem to send all the data I need.
Yes.
You can save attached mail messages as a file, but it will not be in a format that Microsoft Office Outlook will understand. Interestingly enough if you save the file as a .eml then windows live mail will handle the message perfectly.
No webmail service handles attached mail items as outlook and windlows live mail does and gmail ignores them completely.

Need to save a copy of email using imap php and then can be open in outlook express

I had IMAP PHP script which is connecting and reading emails from the mail box.
What i am looking is that i want to save the email on server disk and name it something like testing.eml file. So when later i down those emails and can be viewed in outlook express. Any thoughts how can this be achieved.
Thanks,
See PHP's IMAP reference; here's the core functionality:
$mbox = imap_open ("{localhost:993/imap/ssl}INBOX", "user_id", "password");
$message_count = imap_num_msg($mbox);
if ($message_count > 0) {
$headers = imap_fetchheader($mbox, $message_count, FT_PREFETCHTEXT);
$body = imap_body($mbox, $message_count);
file_put_contents('/your/file/here.eml', $headers . "\n" . $body);
}
imap_close($mbox);
What happens here:
open the mailbox
get message count
if there are any:
get headers of the last one
get body of the last one
save them together in a file
close the mailbox

Categories