how do I add a CC mail address in PHPMailer running on a Linux server?
AddCC method only works on Windows: http://phpmailer.worxware.com/index.php?pg=methods
I tried with this method but the mail never arrives... I also tried with $mail->addCustomHeader('CC: mymail#mail.com') without success.
Thank you.
I had problems with addCC with PHPMailer when there was already a recipient present. In order to fix this, the safemode of the mail function within PHPMailer had to be removed due to the shared server not allowing it. If you turn on errors you will find where the problem is coming from.
First answer here for reference.
PHPmailer multiple recipients error
I have added some lines of code in my application. And I call it tricky things. You can add cc in your code as below :
if($ccList != "") {
$ccRecipients = explode(",",$ccList);
foreach($ccRecipients as $ccRecipient) {
$mailer->AddCC($ccRecipient);
//$mailer->AddAddress($ccRecipient);
}
$mailer->AddCustomHeader("Cc: $ccList");
}
You can change the code to meet your appication needs.
I hope it's working for you :)
Thanks.
Related
Since yesterday I have had problems sending emails with Lumen. I think I have followed all the steps in the documentation correctly, but unfortunately I cannot send anything. Moreover, no error is displayed (I have activated APP_DEBUG=true), and I am sure that the credentials of the smtp server are correct. I also did composer require illuminate/mail.
Here are my modifications in bootstrap/app.php (I have $app->withFacades(); uncommented).
Here is my build function content: return $this->view('emails.mailTemplate', ['message' => $this->message]);.
And the line of code that ask to send mail: Mail::to("wewanthalflifethree#gmail.com")->send(new sendMail($destEmail, $subject, $message));.
Did I do something wrong? :/
Thx in advance for help!
EDIT: I just noticed something, the code stop working when I send the mail. If I add an echo after Mail::send, it will be appear on the page.
I have a problem with the Exceptions handler. By following this answer (which consists in adding a dd in the render function of Handler.php), I am now able to see what's going wrong.
So, here is the reason why my mail didn't send and why my page turned blank: Object of class Illuminate\Mail\Message could not be converted to string (View: /home/serveur-web/api.sl-projects.com/resources/views/emails/mailTemplate.blade.php).
The problem came from the fact that I was using the variable name $message, and this causes problems because it seems to be used in the class that handles the mails. My problem was therefore solved by renaming this variable $mailContent.
I hope this will help other people. :D
I've been searching a lot, but can't really find what i exactly need.
Im running a shop-online using XAMPP, and what i want is send emails to the customers with their order but using a specific function.
What this fuction does, is to hide some characters (for security purpose) on the email sent to customers. So i've made the function (looking on internet), but i want to test it now.
This is my function (if it's wrong, i'd really appreciate some help):
<?php
function xtc_hide_iban ($iban) {
$length = strlen($iban);
$lchars = substr($iban,0 ,5);
$rchars = substr($iban, -5);
$iban_hidden = $lchars.str_repeat('*',$length-10).$rchars;
return $iban_hidden;
}
?>
I think it's pretty obvious what i try to do, but i will still explain it:
Get the $iban from customers, and show only the first and last 5
characters when the email is sent e.G
Your IBAN is 'DE123************56789'
So, for now i can send emails from Mercury mail server to 'root#localhost',account i made on thunderbird, (it's the only account that worked for me, because any other with the same server, like 'anyname#localhost' didn't work or couldn't be created, and those who were create with imap before couldn't access to the inbox "could not connected to server, connection refuse", anyway this works with POP3)
Following what i looked before, is that somehow and somewhere i can put a *.php on Mercury folder so i will get a template of how to send the mails (headers, subject,body,etc).
My main question is how and where to do that? make a test php file to make sure my code is doing what i want to do
Thanks in advance
I am using fake mail for windows, For long time i got a problem with the FIRST mail i am sending, What i mean is that for example i am using php so i will use this line:
mail("example#gmail.com", "hey", "bye");
If i will load the page with this mail function for the first time the mail function will return false, But the second time and third and so on it will work, But, After some time i can not determine how long exactly, I can say the gmail mail server "going to sleep", And again when i am sending a mail for the first time its like, Ohh you need a mail to send give me a second(the first mail return false), After the mail server got the second it wanted it will send the mail(return true), I did follow this tut, The error appear at the error.log is: Connection Closed Gracefully., Now as i see it there is a problem on my gmail account(some setting i should change), Anyway If anyone got any idea i will be very thankful, Thank you all and have a nice day.
After researching this bug, it seems to be a bug of the mail() function. One alternative is to download the phpMailer library, and implement your mail function there. The other alternative, since you say that the second time it always works, is:
if (!mail("example#gmail.com", "hey", "bye"))
mail("example#gmail.com", "hey", "bye");
In other words, if it fails once then you try again. You might insert a 300-milisecond pause there in case Google needs some time to come back from sleep.
I'm having trouble when sending emails thorough the mail() function.
I have a script that works perfectly fine for an email address like name#domain.com but when the first part of the email is something with a dot like name.surname#domain.com it doesn't work and returns this error :
Warning: mail() [function.mail ]: SMTP server response: 554 : Recipient address rejected: Relay access denied in confirmed.php on line 119
I am using real email address but have changed it in the above example.
Any thoughts - I'm not a php master but surely there is an easy way to send emails to address with a 2 part first section??
Thanks in advance
Ali
It is not PHP's fault. It is your SMTP-server. Check mail log i.e. /var/log/mail.log and see if it puts out anything. My best guess is that your relaying is missconfigured.
If the code below fails with this error, then DeeD is partially correct - but it's not relaying which is broken - the address re-writing rules are completely ^&*(ed up.
<php
mail('name.surname#domain.com','hello','test');
?>
Also try:
However this would be a phenomonally stupid error on the part of the person who set up the MTA. I susepct its much more likely that code elsewhere may be modifying the address before the call to mail(...) or that your analysis is incomplete. If this is the case, then neither of the tests above will return the original error - instrument your code to find out where the address is being changed.
Alternatively, if the MTA really doesn't like a . in the name - go buy a cattle prod for the person who configured it.
C.
How can i send mails through the php script??
I am trying to do somthing like this:
for($k=0;$k<=$x->length-1;$k++)
{
for($l=0;$l<=$j-1;$l++)
{
if($y->item($k)->nodeValue==$JobNoArr[$l] && $AcceptanceDateArr[$l]=='0000-00-00')
{
//echo $v->item($k)->nodeValue ;
$email = $v->item($k)->nodeValue . ",";
$to = $email;
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: someother.valid#email.adr";
mail($to,$subject,$txt,$headers);
}
}
}
Please help me in this issue.
Best
Zeeshan
I strongly advise against sending mail using PHP's mail() function. Composing valid emails and delivering them successfully is trickier than it seems at first glance. There is encoding, putting parts together, validation & sanitation, error reporting (more than bool mail(...)), support for authentication and on and on ... The mail() function does not offer any of these things.
Try SwiftMailer or similar. You can configure it to use PHP's mail() function and so much more. I highly recommend it.
You're trying too much all at once. Try going one step at a time. First send a simple email, with hard-coded parameters to get that working, then troubleshoot it within the context of your nested loops.
the problem is mail function is very unreliable, especially when sending large amount of emails.
i would recommend looking into PHPmailer library (uses direct SMTP connection):
http://phpmailer.codeworxtech.com/
The code (the inner most block) looks correct. Make sure your environment is setup correctly.
http://ca3.php.net/manual/en/mail.setup.php
first do
echo $result = mail($to,$subject,$txt,$headers);
and see what u get , error ?
I recommend to use a class such phpMailer
why you have comma in the end of ths line ?
$email = $v->item($k)->nodeValue . ",";
you send to one mail every time.
php-s mail function uses sendmail as a MTA, so if some mails go through and some not, I would look at sendmail's log for errors.
If you are on a shared web host, or your home computer, the main domain for the server will be something like
server.your-isp-or-host.com
The spam filter will then see the email claiming to be from
yourdomain.com
when it really came from the first address, and would then delete it.
This would explain the hit-and-miss nature of your error.
If you are on a dedicated server, or a static IP pointing to your home computer with properly set up DNS, the above does not apply.
if it works sending emails to gmail then it should work fine sending emails to yahoo too
you may find that the issue is not the sending of the emails, but maybe yahoo is marking them as spam or blocking them at the gateway
i notice you are appending a comma to the end of the email address, what is the point of that ?
there may be other problems, are your loops correct, are they covering all the cases you expected.
are you sending thousands of emails ? can your mta handle the rate at which you are putting emails into the queue
is your script hitting max_execution time and stopping ?