i want to send email to my 600 clients through php email. but the loop works till 20 contacts, after that it show 500 internal server error...
i am using go daddy server.
<?php
for($x=1;$x<=600;$x++)
{
$con = mysqli_connect("host","database","password");
if (!$con){die('Could not connect: ' . mysqli_error($con));}
mysqli_select_db($con,"database");
$sql="SELECT email FROM emails Where id = ".$x;
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
$to = $row['email'];
if ($to == "NULL")
{
}
else
{
echo $row['email'];
mysqli_close($con);
// mail($to,"subject","message");
sleep(2);
}
}
?>
Trying to send unlimited mails in a short period time is restricted by most of the hosting servers. If u continuously try to do this, they may even block ur hosting account temporarily or permanent.
But if u want to send unlimited mails there are lot of third party mail services available. U can use those to send unlimited mails.
Related
Actually I want to send a group mail so I have taken the mail id's from db and stored in the variable but when I try to send mail using delimeter as
',' , it shows invalid email id
Below code to Take mail id's from db:
while ($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
$word = $row['Email'];
$GetData = $GetData.$word.',';
}
Now $GetData =example1#gmail.com,example2#gmail.com
php mailer
$mail->addAddress$GetData ,user );
When I add the same into add address it is not working
Message could not be sent.Mailer Error: Invalid address: (to):example1#gmail.com,example2#gmail.com
Note:
if single id then it is sending successfully , so seems like issue with my side so need assistance on this.
You need to use addAddress for each recipient, you are kind of mixing the old headers style with the new mail object..
while ($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
$mail->addAddress($row['Email'] , '');
}
I run this script to send to each user an email. Mails are sent ok(one to each user), but in the email sent all the others adresses are shown in the headers.
$all_users = array(); // intialzie array
while ($usuario = mysqli_fetch_array($resultado, MYSQLI_ASSOC)) {
$usermail = $usuario['email'];
$hash = $usuario['hash'];
mysqli_query($dbc, "UPDATE newsletter SET enviado = '1' WHERE email='$usermail' ");
$all_users[] = $usermail; // push all emails first
}
// then send
try {
$email->setTos($all_users)
->setFrom("no_responder#test.com.ar")
->setFromName("test")
->setReplyTo("no_responder#test.com.ar")
->setSubject("Test")
->setHtml('test');
$result = $sendgrid->send($email);
echo "enviado";
} catch(\SendGrid\Exception $e) {
echo $e->getCode() . "\n";
foreach($e->getErrors() as $er) {
echo $er;
}
}
?>
How can i hide other emails while sending them individually using sendgrid (bcc - blind carbon copy)?
Have you updated your SendGrid PHP library? The newest version uses v3 of the WebAPI, which corrects the confusing To: array functionality.
The issue is that what you're doing right now is populating the native SMTP-level To, which is why you can see all the addresses. In the v2 API, you'd need to instead populate the x-smtpapi field's to array, to make sure SendGrid splits out all the addresses.
I'd strongly recommend updating your PHP Library & leveraging the v3 API, which removes this confusion, and lets you setup each recipient in a more logical manner.
I am running a PHP/MySQL server and am using cron jobs to periodically update my customers as well as send automated newsletters, invoices, etc. However, it does not appear to be working, as emails are not getting sent.
The cron jobs are running (checked the logs).
Invoking the script via the browser results in the emails being sent.
Using SSMTP for email transport.
SPF and DKIM records are in place and correct.
I cannot figure out what is going wrong. Here is pseudocode of the email script:
$override_authentication = true;
require_once('../services/shared/connect.php');
$query = "SELECT * FROM `organizations`";
$orgs = mysqli_query($database,$query);
while ($org = mysqli_fetch_array($orgs)) {
// GENERATE EMAIL CONTENT HERE
// Send email to all users
$query = "SELECT `id`, `email`, `avatar`, `gender`, `phone`, `option_textalerts` FROM `users` WHERE `organization` = " . $org['id'] . " AND `option_scheduling` = 'enabled'";
$users = mysqli_query($database, $query);
while($user = mysqli_fetch_array($users)) {
$message = emailGetHeader("Submit Availability for ".date('F Y', mktime(0,0,0,date('n')+1,1,date('Y'))), $user) . $body . emailGetFooter();
$to = $user['email'];
mail($to,"Submit Availability for ".date('F Y', mktime(0,0,0,date('n')+1,1,date('Y'))),$message,emailGetMeta('Leadsheet <email#leadsheet.us>', 'Leadsheet Automailer <no-reply#leadsheet.us>'));
// If enabled, sent a text alert to the phone number on their account
if ($user['option_textalerts'] == 'availability') {
$phone = preg_replace("/[^0-9]/", "", $user['phone']);
$domains = array('txt.att.net', 'myboostmobile.com', 'sms.mycricket.com', 'tmomail.net', 'vtext.com');
foreach ($domains as $domain) {
mail($phone.'#'.$domain, "Availability Reminder",'Please submit your availability for '.date('F Y', mktime(0,0,0,date('n')+1,1,date('Y'))).' on Leadsheet', emailGetMeta('Leadsheet <txt#leadsheet.us>', 'Leadsheet Automailer <no-reply#leadsheet.us>'));
}
}
}
}
mysqli_close($database);
It looks like you are missing an environment variable. look at phpinfo() and compare with your local environment. Alternatively you can just use wget to emulate a browser loading the page.
After consulting a friend, I discovered the answer. The cron engine was executing the script from the root directory, so the relative file name in the require_once wasn't resolving. Adding a cd command before executing the script solved the issue.
The following script was supposed to send email if all conditions are met and echo "success". The problem here is it is returning "success" but email is not being sent. I tried my best to figure out the problem but can't figure out as I am new to PHP. So I am looking for any possible help. Any help will be appreciated. Thank you in advance
$sql = "SELECT id, username FROM user WHERE email='$e' AND activated='1' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($query);
if($numrows > 0){
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$id = $row["id"];
$u = $row["username"];
$emailcut = substr($e, 0, 4);
$randNum = rand(10000,99999);
$tempPass = "$emailcut$randNum";
$hashTempPass = md5($tempPass);
$sql = "UPDATE useroptions SET temp_pass='$hashTempPass' WHERE username='$u' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$to = "$e";
$from = "auto_responder#geniusfree.net";
$headers ="From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$subject ="GeniusFree Password Reset";
$msg = '<h2>Hello '.$u.'</h2><p>This is an automated message from GeniusFree. If you did not recently initiate the Forgot Password process, please disregard this email.</p><p>You indicated that you forgot your login password. We can generate a temporary password for you to log in with, then once logged in you can change your password to anything you like.</p><br /><p>Click here now to apply the temporary password shown below to your account</p><p>If you do not click the link in this email, no changes will be made to your account. In order to set your login password to the temporary password you must click the link above.</p>';
if(mail($to,$subject,$msg,$headers)) {
echo "success";
exit();
} else {
echo "email_send_failed";
exit();
}}
Check the MX entry settings. Highest priority is 0. If you are using your mail server in your host. The first entry should be something like this priority number 0 ---> mail.yoursite.com.
Another way to debug this is to use email trace route. You can do it in cpanel.
Hope this helps.
First you need to configure php to send emails from your server ,if you are running code on your local host machine then you have to configure your php.ini file for sending emails and if code is running on web hosting server then contact them for this issue ,
for configuration details you can refer send mail using xampp in php
if you are using another local server like wamp then you have to separately (download) install sendmail utility on your server.
Hope this works for you
do you run it on the local host? if so , it may does not work there , please test it on the Web Host and let me know the result.
How can I make it so when a user email's to my email address their email text/information is written into a mysql table? So basically extract the contents of a new email and write them into mysql table.
I tried this but I get nothing:
<?php
$imap = imap_open("{gmail.com}", "username", "password");
if( $imap ) {
//Check no.of.msgs
$num = imap_num_msg($imap)
//if there is a message in your inbox
if( $num >0 ) {
//read that mail recently arrived
echo imap_qprint(imap_body($imap, $num));
}
//close the stream
imap_close($imap);
}
?>
We are using an exchange server..I am a coop student so I am not really advanced at this.
I tried this as a test to see if it works, logging in gmail to read email. It didnt work.
<?php
// connect to the mailbox
$m_mail = imap_open("{mail.https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2}INBOX", "username", "password");
//get all messages
$m_search=imap_search ($m_mail, 'ALL ');
// Order results starting from newest message
rsort($m_search);
//loop through and do what's necessary
foreach ($m_search as $onem) {
//get imap header info for obj thang
$headers = imap_headerinfo($m_mail, $onem);
$head = imap_fetchheader($m_mail, $headers->Msgno);
$body = imap_body($m_mail, $headers->Msgno, FT_INTERNAL );
echo $body;
}
//purge messages (if necessary)
imap_expunge($m_mail);
//close mailbox
imap_close($m_mail);
?>
use IMAP functions for that. Set up another email account if necessary. Here's the example code:
// connect to the mailbox
$m_mail = imap_open("{mail.YOURHOST.com:993/imap/ssl/novalidate-cert}INBOX", "address#YOURHOST.com", "YOURPASSWORD");
//get all messages
$m_search=imap_search ($m_mail, 'ALL ');
// Order results starting from newest message
rsort($m_search);
//loop through and do what's necessary
foreach ($m_search as $onem) {
//get imap header info for obj thang
$headers = imap_headerinfo($m_mail, $onem);
$head = imap_fetchheader($m_mail, $headers->Msgno);
$body = imap_body($m_mail, $headers->Msgno, FT_INTERNAL );
//
DO WHAT YOU NEED TO DO HERE - insert to the database, etc
}
//purge messages (if necessary)
imap_expunge($m_mail);
//close mailbox
imap_close($m_mail);
read your mailbox via pop3 or imap and add the new emails to your database
Take a look a this class: http://php.net/manual/en/book.imap.php
you could read the pop3/imap in some intervals.
other method would be to redirect your email to a php script. I don't know which email system you are using on your server but here is an example with postfix.
the pop3/imap method is easier and you don't need to edit your server configs but the second method is faster because your script will start as it receives an email.