/    Sign up×
Community /Pin to ProfileBookmark

Few questions about email sending in php

I have tried several ways to send mail but I hav failed and I m veryyyyyy upset. Now
I have few question about mail sending in php

  • 1.

    I cant/dont use the smtp server of my ISP. Now which server I can send my mail thru?

  • 2.

    I want to use yahoo smtp mail server. Now do I have to set yahoo smtp server name and port in php.ini? Cant I set these (both name and port)dynamically in php. if so, how?

  • 3.If the server name I m using uses authenticated smtp, WHERE and how to put code for user id and password in php .
    If in mail header then in which format?

  • 4. I hav come to know the following things from website of yahoo-
  • Outgoing Mail (SMTP) Server:
    smtp.mail.yahoo.com (Use SSL, port: 465,[b] use authentication[/b])

    I am also giving u my account details
    My yahoo id- [email][email protected][/email] (created 2day for the test)
    password- abcdefg

    Now would anybody pls pls tel me or write me a simple code by which I can send mail without using my Isp’s smtp server. DO I need to use those info. in php.ini . Or is there any way to add them dynamically in php.

    I once tried with the following code but nothing happened

    [code=php]
    <?php
    //mail($recepeint,$subject,$msg,$mailheader);
    //define the receiver of the email
    $to = ‘[email protected]’;
    //define the subject of the email
    $subject = ‘Test email’;
    //define the message to be sent. Each line should be separated with n
    $message = “Hello World!rnThis is my first mail.”;
    //define the headers we want passed. Note that they are separated with rn
    $headers = “From: [email protected]: [email protected]”;
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print “Mail sent”. Otherwise print “Mail failed”
    echo $mail_sent ? “Mail sent” : “Mail failed”;

    echo “Thank You <b>Tanvir</b> for ur message”;
    echo “<p>Your mail address is <p>$to </p>”;
    echo “<p>Your message was <p> $message </p>”;

    ?>
    //I set server=smtp.mail.yahoo.com and port=25 in php.ini and restart the server .
    [/code]

    NB. If I configure php.ini in php code using ini_set(), wouldn’t it be permanent next time. But what happens if I host these php file in another server. There can be a lot other php files trying to do the same thing. Isn’t it a problem.
    I can also send mail using a free smtp server and a mail client in my windows pc which requires default 25 port for smtp. Should I use this port-25 with the above server name smtp.mail.yahoo.com[/code]

    to post a comment
    PHP

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @TJ111Nov 09.2007 — I'd bet money that yahoo's email servers require authentication before sending email. Here's a [url=http://email.about.com/od/emailprogrammingtips/qt/et073006.htm]tutorial[/url] that explains how you can send mail from php that requires smtp authentication, however it requires you to have the PEAR Mail package installed.
    Copy linkTweet thisAlerts:
    @tanvirtonuauthorNov 09.2007 — I'd bet money that yahoo's email servers require authentication before sending email. Here's a [url=http://email.about.com/od/emailprogrammingtips/qt/et073006.htm]tutorial[/url] that explains how you can send mail from php that requires smtp authentication, however it requires you to have the PEAR Mail package installed.[/QUOTE]

    Brother I have just tried it using pear package-

    My code is as follows-
    [code=php]

    include('Mail.php');
    /* mail setup recipients, subject etc */
    $recipients = '[email protected]';
    $headers['From'] = '[email protected]';

    $headers['To'] = '[email protected]';
    $headers['Subject'] = 'ME HERE';
    $mailmsg = 'Hello, This is a test.';
    /* SMTP server name, port, user/passwd */
    $smtpinfo['host'] = 'smtp.mail.yahoo.com';
    $smtpinfo['port'] = '25';
    $smtpinfo['auth'] = true;
    $smtpinfo['username'] = 'bhonest_4ever2007';
    $smtpinfo['password'] = 'abcdefg';
    /* Create the mail object using the Mail::factory method */
    $mail_object =& Mail::factory('smtp', $smtpinfo);
    /* Ok send mail */
    $mail_object->send($recipients, $headers, $mailmsg);
    ?>

    [/code]


    But the mail is not sent. I have shut down all firewall or antivirus and tried again but didn't work. Wud anybody pls try my code and tell me if it works so that I can be sure that the problem is not with my code.One more thing which port should I use-default 25 or 465 which uses SSL and authentication . Pls help me.
    ×

    Success!

    Help @tanvirtonu spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.26,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...