Page 1 of 1

Send Mail with using PHP

Posted: Tue Oct 20, 2009 2:07 am
by winniekoh
helo, everybody here.. i had a problem about to send email out.
first, i had setting a email account in Ms Outlook 2007
second, i change the [mail_function] in php.ini
like this

[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port =465


; For Win32 only.
;sendmail_from = mbership.co@gmail.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =


then i had create a email form called sendmymail.php

Code: Select all

<?
include("ch19_include.php");
if(!$_POST){
    echo "<html>
    <head>
    <title>Send a NewLetter</title>
    </head>
    <body>
    <h1>Send a Newletter</h1>
    <form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
    <p><strong>Subject:</strong><br/>
    <input type=\"text\" name=\"subject\" size=\"30\"></p>
    <p><strong>Mail Body:</strong><br/>
    <textarea name=\"message\" cols=\"50\" rows=\"10\"
        wrap=\"virtual\"></textarea>
    <p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p>
    </form>
    </body>
    </html>";
} else if($_POST){
    if(($_POST["subject"]=="")||($_POST["message"]=="")){
    header("Location: sendmyemail.php");
    exit;
    }
    doDB();
    if(mysqli_connect_errno()){
    printf("Connect failed:%s\n",mysqli_connect_error());
    exit();
    } else {
    $sql="SELECT email FROM subscribers";
    $result=mysqli_query($mysqli, $sql)
    or die(mysqli_error($mysqli));
    
    $mailheaders="From:Your Mailing List <mbership.co@gmail.com>";
    while($row=mysqli_fetch_array($result)){
    set_time_limit(0);
    $email=$row["email"];
    mail("$email",stripslashes($_POST["subject"]),stripslashes($_POST["message"]),$mailheaders);
    echo "newletter sent to:".$email."<br/>";
    }
    mysqli_free_result($result);
    mysqli_close($mysqli);
    }
}
?>
another file is ch19_include.php (this is to link to the mysql database)

Code: Select all

<?php
function doDB(){
global $mysqli;
$mysqli=mysqli_connect("localhost","root","","dbase_azizi");
 
if(mysqli_connect_errno()){
printf("Connect failed:%s\n",mysqli_connect_error());
exit();
    }
}
 
function emailChecker($email){
global $mysqli,$check_res;
 
$check_sql="SELECT id from subscribers
where email='".$email."'";
$check_res=mysqli_query($mysqli,$check_sql)
or die(mysqli_error($mysqli));
}
?>
the problem is, i had do all when i try and send it, it came out this error

Re: Send Mail with using PHP

Posted: Tue Oct 20, 2009 3:17 am
by requinix
winniekoh wrote:the problem is, i had do all when i try and send it, it came out this error
Which is... what?

Re: Send Mail with using PHP

Posted: Tue Oct 20, 2009 5:39 am
by jegan.aaodis
Hi

Can you able to get the values from database.
If yes
then this is the problem
mail("$email",stripslashes($_POST["subject"]),stripslashes($_POST["message"]),$mailheaders);
mail($email,stripslashes($_POST["subject"]),stripslashes($_POST["message"]),$mailheaders);

You have given double codes in $email.
If it is value then we can give double codes or else no need to specify.

Thanks

Re: Send Mail with using PHP

Posted: Tue Oct 20, 2009 7:16 pm
by winniekoh
tasairis wrote:
winniekoh wrote:the problem is, i had do all when i try and send it, it came out this error
Which is... what?
it will keep load..
like can't send out