i try to send a mail from a bash script with the following code
notify_by_mail () {
echo "TEST BODY" | mail --attach=$LOG_PATH -aFROM:$1 -s "Borg backup failed" $2
}
The problem is, what I try to echo to mail is also handled as an attachment but I want to have it as the body. When I dont send an attachment it behaves like I would. Could anyone please tell me whats going wrong?
It tried around with mail and searched long for the options but I cant figure out what I do wrong.
Thanks a lot!
Related
I'm using sendmail in a perl script, and would like to get the "To" address from the user who invoked the script.
In other words I would like the from and to address to be same. How do I do that ?
Thanks.
Given your code of
open(Mail, "|/usr/sbin/sendmail -t");
print MAIL "To: $to\n"
print MAIL $msg
close(MAIL)
I'll suggest adding in front of that
$to ||= $ENV{SUDO_USER} || $ENV{USERNAME} || $ENV{LOGNAME} || $ENV{USER} || getpwuid $<;
While I'm at it, I'll recommend you add an extra newline after your last header, so that if $msg just happens to start with something that might look like a header, it won't be used as a header. Unless that's actually behavior you're depending on... (But I'd recommend not depending on that behavior...)
There's not really an "email address" property of a user. If you're just going through a local MTA, the user's address is generally their username, which you can retrieve with scalar getpwuid $> on Unixlike systems.
I have many different templates for sending emails!
So I made a php file (lets call it send.php) which I want to "call" with file_get_contents and some parameters (which decide which template should be used) from another File like finish.php!
The different Paths:
templates ("/phpmailer/templates/")
send.php ("/phpmailer/send.php")
finish.php ("/courses/finish.php")
The working Link itself looks something like this:
http://www.myadress.at/phpmailer/send.php?template=booking&email=bla#bla.at&name=Christopher
Inside the send.php I check if the template exists, if YES then the Mail will be sent!
if (file_exists(dirname(__FILE__)."/templates/".$template.".php") AND isset($email)) {
$mail->msgHTML(file_get_contents('https://www.myadress.at/phpmailer/templates/'.$template.'.php?'.$parameter.''), dirname(__FILE__));
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
else
{
ERROR
}
Now when somebody books a course or something, after filling out the signup-form, I want to send an Confirmation Email from the file, the person is landing after the form (finish.php)
My finish.php file hast just a file_get_contents with the Path to my send.php file:
$sendmail= file_get_contents("https://www.myadress.at/phpmailer/send.php?template=booking-confirmation&email=".urlencode($email)."");
Now the problem is, when trying to use it from finish.php with file_get_contents, he says the Template doesnt exist... When copying the same link to firefox, everything works.. The name of the template is right!
I've tried the following things:
(file_exists(dirname(__FILE__)."/templates/".$template.".php") - with dirname
(file_exists("/templates/".$template.".php") - the normal path
(file_exists("/phpmailer/templates/".$template.".php") - full path
(file_exists("http://www.myadress.at/phpmailer/templates/".$template.".php") - normal url
Pleaaase help me ^^ Maybe this isnt possible haha
Okay, now everything works fine!
The problem was caused by either by some spaces in the url or because I didn't urlencode every single variable..
ahhhh so many time!
I am trying to send a 2nd email to my sites admin when a user registers.
I made a postHook snippet that sends an email but it didnt work - the Registration process worked as expected, but I got no 2nd email from the hook.
In testing I set the hook from postHook to preHook and tried again - this time the form didnt process at all - no new user was created and no activation email was sent. It didnt even redirect to the submittedResourceId.
So, I deleted everything in my preHook Snippet, except the return true; and tried again - still nothing.
It appears Login wont run any Hooks at all. I have no idea why.
Would anyone be able to suggest any fixes?
My register snippet is:
[[!Register?
&submitVar=`registerbtn`
&activationResourceId=`19`
&activationEmailTpl=`lgnActivateEmailTpl`
&activationEmailSubject=`Thanks for Registering!`
&submittedResourceId=`23`
&usergroups=`2`
&validate=`nospam:blank,
username:required:minLength=^6^,
password:required:minLength=^6^,
password_confirm:password_confirm=^password^,
fullname:required,
email:required:email`
&preHooks=`adminEmailHook`
]]
I've done something similar before. There is my code:
[[!Register? &postHooks=`sendMessageToAdmin`
Snippet sendMessageToAdmin:
<?php
$message = 'Auto message:<br><br>A new user signed up: '.$hook->getValue('fullname') . ', using email address '.$hook->getValue('email').'.';
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,'info#domain.com');
$modx->mail->set(modMail::MAIL_FROM_NAME,'My website');
$modx->mail->set(modMail::MAIL_SENDER,'Auto message from my website');
$modx->mail->set(modMail::MAIL_SUBJECT,'Someone signed up');
$modx->mail->address('to','info#domain.com');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'sendMessageToAdmin: An error occurred while trying to send the email: '.$err);
}
$modx->mail->reset();
/* tell our snippet we're good and can continue */
return true;
I've been using PHPMailer successfully for a couple of years. I just refreshed my PHPMailer class from their github site, and now my server throws 500 errors. I tracked down the problem to this line (simplified for this post):
$mail->Body = "<p>Hello World</p>";
All of the example that I see on the worxware website these days show the body of the email being read from a file like this:
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
I also tried modifying my code to use the MsgHTML syntax, but I still have the same result:
$body = "<p>Hello World</p>";
$mail->MsgHTML($body);
I can't imagine that it matters whether this body gets populated from a file or from a local variable, but nothing that I try works. What am I missing? Thanks!
$output = str_replace(array("\n","\r"),"",$output);
try this
Please I am new to cron jobs and only heard of it recently.
The thing is I am trying to send a message to myself via a phpscript.
I need the cron job to read the php cript and send the appropriate message.
here is the php self mailer I have in place.
<?php
$recipient = "*******#gmail.com";
$subject = "Flight Status";
$body = "Flight has just landed.";
if(mail($recipient, $subject, $body))
{
echo("<p>Message successfully sent</p>");
}
else
{
echo("<p>Message Delivery failed </p>");
}
?>
you can read the manual for cron with man 5 crontab. It contain example as well.
for example,
# run at 2:15pm on the first of every month -- output mailed to paul
15 14 1 * * $HOME/bin/flight.php
Sending email through phone is complicated, as you need a smtp server set up. A better solution would be to send yourself a message via a chat application.
I personally use nimrod for this : https://www.nimrod-messenger.io
It's messenger only but other chat systems are planned.